Repository navigation
Race in func_get_annotations under free-threading #128714
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jan 10, 2025 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes
on Jan 10, 2025 Besides, it seems the the range object also has data races when I run the test suites
test_free_threadingunder FT build:WARNING: ThreadSanitizer: data race (pid=2516929) Read of size 8 at 0x7f9cbfaa66a0 by thread T392: #0 rangeiter_next ../Objects/rangeobject.c:819 (python+0x21713e) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #1 zip_next ../Python/bltinmodule.c:3111 (python+0x313553) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #2 builtin_next ../Python/bltinmodule.c:1651 (python+0x3155bb) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #3 _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:1510 (python+0x32d5df) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #4 _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:116 (python+0x358df3) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #5 _PyEval_Vector ../Python/ceval.c:1913 (python+0x35904f) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #6 _PyFunction_Vectorcall ../Objects/call.c:413 (python+0x165e43) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #7 _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:167 (python+0x16a189) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #8 method_vectorcall ../Objects/classobject.c:72 (python+0x16a477) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #9 _PyVectorcall_Call ../Objects/call.c:273 (python+0x167f38) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #10 _PyObject_Call ../Objects/call.c:348 (python+0x168362) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #11 PyObject_Call ../Objects/call.c:373 (python+0x1683c2) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #12 thread_run ../Modules/_threadmodule.c:354 (python+0x4bcd17) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #13 pythread_wrapper ../Python/thread_pthread.h:242 (python+0x41af14) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) Previous write of size 8 at 0x7f9cbfaa66a0 by thread T394: #0 rangeiter_next ../Objects/rangeobject.c:822 (python+0x217198) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #1 zip_next ../Python/bltinmodule.c:3111 (python+0x313553) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #2 builtin_next ../Python/bltinmodule.c:1651 (python+0x3155bb) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #3 _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:1510 (python+0x32d5df) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #4 _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:116 (python+0x358df3) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #5 _PyEval_Vector ../Python/ceval.c:1913 (python+0x35904f) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #6 _PyFunction_Vectorcall ../Objects/call.c:413 (python+0x165e43) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #7 _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:167 (python+0x16a189) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #8 method_vectorcall ../Objects/classobject.c:72 (python+0x16a477) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #9 _PyVectorcall_Call ../Objects/call.c:273 (python+0x167f38) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #10 _PyObject_Call ../Objects/call.c:348 (python+0x168362) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #11 PyObject_Call ../Objects/call.c:373 (python+0x1683c2) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #12 thread_run ../Modules/_threadmodule.c:354 (python+0x4bcd17) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8) #13 pythread_wrapper ../Python/thread_pthread.h:242 (python+0x41af14) (BuildId: 3d91448656453eabf7067b9e5af5b37997c21fc8)Here's a somewhat similar looking race on
type_get_annotations:WARNING: ThreadSanitizer: data race (pid=355399) Read of size 4 at 0x7e07ad0c2190 by thread T65 (mutexes: read M0): #0 PyType_Modified /__w/jax/jax/cpython/Objects/typeobject.c:1059:15 (python3.13+0x305823) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #1 type_get_annotations /__w/jax/jax/cpython/Objects/typeobject.c:1790:17 (python3.13+0x305823) #2 getset_get /__w/jax/jax/cpython/Objects/descrobject.c:193:16 (python3.13+0x1ff5e8) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #3 _Py_type_getattro_impl /__w/jax/jax/cpython/Objects/typeobject.c:5411:19 (python3.13+0x2e92cd) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #4 PyObject_GetOptionalAttr /__w/jax/jax/cpython/Objects/object.c:1307:19 (python3.13+0x292eb1) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #5 builtin_getattr /__w/jax/jax/cpython/Python/bltinmodule.c:1200:13 (python3.13+0x3d8d79) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #6 cfunction_vectorcall_FASTCALL /__w/jax/jax/cpython/Objects/methodobject.c:425:24 (python3.13+0x289b7b) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #7 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1ead4a) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) ... Previous atomic write of size 4 at 0x7e07ad0c2190 by thread T67 (mutexes: read M0): #0 _Py_atomic_store_uint32_relaxed /__w/jax/jax/cpython/./Include/cpython/pyatomic_gcc.h:461:3 (python3.13+0x2e5090) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #1 set_version_unlocked /__w/jax/jax/cpython/Objects/typeobject.c:978:5 (python3.13+0x2e5090) #2 type_modified_unlocked /__w/jax/jax/cpython/Objects/typeobject.c:1047:5 (python3.13+0x2e5090) #3 PyType_Modified /__w/jax/jax/cpython/Objects/typeobject.c:1064:5 (python3.13+0x3058d4) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #4 type_get_annotations /__w/jax/jax/cpython/Objects/typeobject.c:1790:17 (python3.13+0x3058d4) #5 getset_get /__w/jax/jax/cpython/Objects/descrobject.c:193:16 (python3.13+0x1ff5e8) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #6 _Py_type_getattro_impl /__w/jax/jax/cpython/Objects/typeobject.c:5411:19 (python3.13+0x2e92cd) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) #7 PyObject_GetOptionalAttr /__w/jax/jax/cpython/Objects/object.c:1307:19 (python3.13+0x292eb1) (BuildId: c9937216e103905f871b62bf50b66fc5a8e96f80) ...I figured it might be simplest just to add this here, but I can open a new issue if you like!
- added 2 commits that reference this issue
on Jan 31, 2025 I figured it might be simplest just to add this here, but I can open a new issue if you like!
Please create a new issue for it, the getters and setters of typeobject are missing critical section which would have to be added independent of function object fixes.
- added a commit that references this issue
on Feb 6, 2025 - added a commit that references this issue
on Feb 24, 2025
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
With CPython 3.13 from commit 65da5db TSAN reports the following race, which looks right: the initialization of
p->func_annotationsis racy.Reproducer:
TSAN report (first race):
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
__annotate__,__annotations__and__type_params__in free-threading build (GH-129016) #129729