Skip to content

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.

"""
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