Skip to content

Make KeyBundle update() thread safe #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

jschlyter
Copy link
Collaborator

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

@jschlyter jschlyter requested a review from rohe April 7, 2021 08:27
@rohe rohe merged commit 0c93ee4 into IdentityPython:develop Apr 7, 2021
@jschlyter jschlyter deleted the key_bundle_thread_safe branch April 7, 2021 13:56
Copy link
Contributor

@janste63 janste63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -507,34 +508,35 @@ def update(self):
:return: True if update was ok or False if we encountered an error during update.
"""
if self.source:
_old_keys = self._keys # just in case
with threading.Lock():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a global variable with the lock. This will create a new Lock() for each call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in c9e59bc, will address the lookup while updating issue as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants