Race between PyMember_GetOne and PyMember_SetOne for _Py_T_OBJECT members under freethreading #128144
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
PyMember_GetOne
does not use an atomic read when reading a_Py_T_OBJECT
member, even thoughPyMember_SetOne
uses an atomic write when updating such a member.To demonstrate this, I'm using
builtin_function_or_method
's__module__
, which is an example of a writeable_Py_T_OBJECT
member in CPython's codebase. I don't know what field exactly was the source of the race when I found it in another codebase; it may or may not have been the same.To reproduce, run the following code under CPython 3.13.1t with thread-sanitizer enabled:
and you'll get this race:
The fix is presumably to make the read atomic as well.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: