You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Abort in free-threaded build due to mutation of ChainMap of a Counter in threads #126366
It looks like this is some sort of 3.14 regression. On 3.13, it doesn't crash; instead, it just spams RuntimeErrors (which might also be a bug, but let's focus on this first).
This is probably a data race, but that scares me because nearly everything here is pure Python. Valgrind is pointing at native generators being the culprit, I'm looking into it.
Yeah, Sam mentioned that in my (closed) PR. The main concern with merging gh-120327 is that it will have a heavy performance hit on generators. IIRC, the relation with generators in this issue is that collections.abc.Iterable (which ChainMap inherits from) uses a generator in its __iter__.
I think this is because in dictiter_iternext_threadsafe load of dict keys is done with relaxed ordering but it should be done with acquire ordering because keys are stored using release ordering when resizing. Changing the load from relaxed to acquire memory ordering fixes the race.
Activity
ZeroIntensity commentedon Nov 3, 2024
It looks like this is some sort of 3.14 regression. On 3.13, it doesn't crash; instead, it just spams
RuntimeErrors (which might also be a bug, but let's focus on this first).This is probably a data race, but that scares me because nearly everything here is pure Python. Valgrind is pointing at native generators being the culprit, I'm looking into it.
ZeroIntensity commentedon Nov 3, 2024
Yeah, there's a thread safety issue with native generators (or possibly with
list). Here's a smaller reproducer:ZeroIntensity commentedon Nov 3, 2024
I had to split the fix up into two PRs because of backporting: gh-126369 and gh-126371
gh-126366: Fix crash if `__iter__` raises an exception during `yield …
vstinner commentedon Nov 6, 2024
See also #120321 issue and #120327 fix.
ZeroIntensity commentedon Nov 6, 2024
Yeah, Sam mentioned that in my (closed) PR. The main concern with merging gh-120327 is that it will have a heavy performance hit on generators. IIRC, the relation with generators in this issue is that
collections.abc.Iterable(whichChainMapinherits from) uses a generator in its__iter__.pythongh-126366: Fix crash if `__iter__` raises an exception during `…
pythongh-126366: Fix crash if `__iter__` raises an exception during `…
kumaraditya303 commentedon Apr 18, 2025
On current main branch it doesn't crash but there is the following tsan warning:
I think this is because in
dictiter_iternext_threadsafeload of dict keys is done with relaxed ordering but it should be done with acquire ordering because keys are stored using release ordering when resizing. Changing the load from relaxed to acquire memory ordering fixes the race.gh-126366: fix thread safety of dict key iterator (#132693)