Make KeyBundle update() thread safe#81
Merged
rohe merged 2 commits intoIdentityPython:developfrom Apr 7, 2021
Merged
Conversation
rohe
approved these changes
Apr 7, 2021
janste63
suggested changes
Apr 7, 2021
Contributor
janste63
left a comment
There was a problem hiding this comment.
This will not work since self._keys still will be read while we update the keys. You need lock these also or better, read the new keys into a local variable first and then assign it to self._keys.
| """ | ||
| if self.source: | ||
| _old_keys = self._keys # just in case | ||
| with threading.Lock(): |
Contributor
There was a problem hiding this comment.
You need a global variable with the lock. This will create a new Lock() for each call.
Collaborator
Author
There was a problem hiding this comment.
Will fix, thanks!
Collaborator
Author
There was a problem hiding this comment.
Fix in c9e59bc, will address the lookup while updating issue as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If multiple threads tries to access keys and the access triggers an update, the bundle will sometimes end up as empty. This PR introduces a lock for
KeyBundle.update()to make it thread safe.Reported by @janste63