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
Data race in intern_common when interning str objects in the free threading build #129701
There are a few thread-safety issues with intern_common:
It can return a string that's not marked as interned because we insert into interned before we mark the string as interned. This can be fixed with some additional locking.
The Py_SET_REFCNT(s, Py_REFCNT(s) - 2) modification is not thread-safe with respect to other reference count modifications in the free threading build
Thanks. Is this is with 3.13? I think that one was fixed in #128196, but it's not backported to 3.13. That particular PR changes the data types of public fields, so I don't think we can backport it.
It might be worth doing the thread sanitizer tests on 3.14. cc @ngoldbaum
I want to re-do the TSAN PyO3 tests with 3.14, but I need to update the FFI definitions first. Generally PyO3 doesn't add support for new python versions until beta 1 to avoid dealing with churn.
Activity
lysnikolaou commentedon Feb 13, 2025
I hit this while testing PyYAML (though the TSAN stack trace was slightly different). Are you going to work on this @colesbury?
colesbury commentedon Feb 13, 2025
Yes, I'll probably put up a PR today.
Would you please share the TSAN stack trace?
pythongh-129701: Fix a data race in `intern_common` in the free threa…
lysnikolaou commentedon Feb 13, 2025
Sure, here it is.
colesbury commentedon Feb 13, 2025
Thanks. Is this is with 3.13? I think that one was fixed in #128196, but it's not backported to 3.13. That particular PR changes the data types of public fields, so I don't think we can backport it.
It might be worth doing the thread sanitizer tests on 3.14. cc @ngoldbaum
ngoldbaum commentedon Feb 13, 2025
I think I've seen similar tracebacks on 3.13 with PyO3 about interning strings. See this line in the gist from this PyO3 issue.
I want to re-do the TSAN PyO3 tests with 3.14, but I need to update the FFI definitions first. Generally PyO3 doesn't add support for new python versions until beta 1 to avoid dealing with churn.
pythongh-129701: Fix a data race in `intern_common` in the free threa…
lysnikolaou commentedon Feb 13, 2025
Yes, it's with 3.13.2. I'll try 3.14 later today or early tomorrow.
lysnikolaou commentedon Feb 14, 2025
FWIW I did verify that the
unicode_eqstack trace does not appear under 3.14.gh-129701: Fix a data race in `intern_common` in the free threaded bu…
colesbury commentedon Feb 25, 2025
I'm going to close this as the only remaining issue is that _Py_SetImmortal is not thread-safe in some circumstances, which is tracked in:
_Py_SetImmortalmust be run on allocating thread (no-gil) #113956