-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Race condition in WeakKeyDictionary/WeakValueDictionary #89967
Comments
The issue described bpo-7105 (and maybe bpo-7060) still exists due to a race condition in WeakKeyDictionary. This shows up as test failure that looks like: test test_weakref failed -- Traceback (most recent call last):
File "Lib/test/test_weakref.py", line 1960, in test_threaded_weak_value_dict_deepcopy
self.check_threaded_weak_dict_copy(weakref.WeakValueDictionary, True)
File "Lib/test/test_weakref.py", line 1940, in check_threaded_weak_dict_copy
raise exc[0]
File "Lib/test/test_weakref.py", line 1897, in dict_copy
_ = copy.deepcopy(d)
File "Lib/copy.py", line 153, in deepcopy
y = copier(memo)
File "Lib/weakref.py", line 189, in __deepcopy__
for key, wr in self.data.items():
RuntimeError: dictionary changed size during iteration The cause is that the check of "self._iterating" and the call to "_atomic_removal" are not performed atomically together. By the time _atomic_removal() is called, an iteration might have already started. Lines 109 to 114 in ec382fa
|
kumaraditya303
changed the title
Race condition in WeakKeyDictionary/WeakKeyDictionary
Race condition in WeakKeyDictionary/WeakValueDictionary
Oct 11, 2024
kumaraditya303
added a commit
that referenced
this issue
Oct 13, 2024
…125325) Make `WeakKeyDictionary` and `WeakValueDictionary` thread safe by copying the underlying the dict before iterating over it.
kumaraditya303
added
3.14
new features, bugs and security fixes
and removed
3.11
only security fixes
3.10
only security fixes
3.9
only security fixes
labels
Oct 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: