Repository navigation
Race on _PyRuntime.signals.unhandled_keyboard_interrupt when calling eval() concurrently in free-threading mode #128130
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 20, 2024 - addedextension-modulesC modules in the Modules dirC modules in the Modules dir3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes
on Dec 20, 2024 - changed the title
[-]Race when calling collections.namedtuple() concurrently in free-threading mode[/-][+]Race on `_PyRuntime.signals.unhandled_keyboard_interrupt` when calling `eval()` concurrently in free-threading mode[/+]on Dec 21, 2024 I think there's a race condition here even in the default build where a concurrent
eval()may wipe out theunhandled_keyboard_interruptfrom the main thread.Also seen when running
./python -m test test_exceptions --parallel-threads=10 -vunder Tsan in main (3.14). It's in a different function, but still on_PyRuntime.signals.unhandled_keyboard_interrupt.WARNING: ThreadSanitizer: data race (pid=990837) Write of size 4 at 0x555555cd2530 by thread T595: #0 _PyErr_Display Python/pythonrun.c:1127 (python+0x43bad3) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #1 thread_excepthook_file Modules/_threadmodule.c:2189 (python+0x52f068) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #2 thread_excepthook Modules/_threadmodule.c:2268 (python+0x52f068) #3 cfunction_vectorcall_O Objects/methodobject.c:523 (python+0x1fd56e) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #4 _PyObject_VectorcallTstate Include/internal/pycore_call.h:167 (python+0x149161) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #5 PyObject_Vectorcall Objects/call.c:327 (python+0x149161) #6 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1367 (python+0x8a1ff) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #7 _PyEval_EvalFrame Include/internal/pycore_ceval.h:116 (python+0x37d7fc) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #8 _PyEval_Vector Python/ceval.c:1761 (python+0x37d7fc) #9 _PyFunction_Vectorcall Objects/call.c:413 (python+0x14957b) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #10 _PyObject_VectorcallTstate Include/internal/pycore_call.h:167 (python+0x14f138) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #11 method_vectorcall Objects/classobject.c:72 (python+0x14f138) #12 _PyVectorcall_Call Objects/call.c:273 (python+0x14b9b7) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #13 _PyObject_Call Objects/call.c:348 (python+0x14be80) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #14 PyObject_Call Objects/call.c:373 (python+0x14be80) #15 thread_run Modules/_threadmodule.c:354 (python+0x52e235) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #16 pythread_wrapper Python/thread_pthread.h:242 (python+0x466079) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) Previous write of size 4 at 0x555555cd2530 by thread T599: #0 _PyErr_Display Python/pythonrun.c:1127 (python+0x43bad3) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #1 thread_excepthook_file Modules/_threadmodule.c:2189 (python+0x52f068) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #2 thread_excepthook Modules/_threadmodule.c:2268 (python+0x52f068) #3 cfunction_vectorcall_O Objects/methodobject.c:523 (python+0x1fd56e) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #4 _PyObject_VectorcallTstate Include/internal/pycore_call.h:167 (python+0x149161) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #5 PyObject_Vectorcall Objects/call.c:327 (python+0x149161) #6 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1367 (python+0x8a1ff) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #7 _PyEval_EvalFrame Include/internal/pycore_ceval.h:116 (python+0x37d7fc) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #8 _PyEval_Vector Python/ceval.c:1761 (python+0x37d7fc) #9 _PyFunction_Vectorcall Objects/call.c:413 (python+0x14957b) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #10 _PyObject_VectorcallTstate Include/internal/pycore_call.h:167 (python+0x14f138) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #11 method_vectorcall Objects/classobject.c:72 (python+0x14f138) #12 _PyVectorcall_Call Objects/call.c:273 (python+0x14b9b7) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #13 _PyObject_Call Objects/call.c:348 (python+0x14be80) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #14 PyObject_Call Objects/call.c:373 (python+0x14be80) #15 thread_run Modules/_threadmodule.c:354 (python+0x52e235) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2) #16 pythread_wrapper Python/thread_pthread.h:242 (python+0x466079) (BuildId: f460519d72c998d19781985effd47fe68db6f3c2)Closing, on the assumption the PR linked above fixed this!
Not fixed on the 3.13 branch:
WARNING: ThreadSanitizer: data race (pid=113280) Write of size 4 at 0x567f47699168 by thread T6 (mutexes: read M0): #0 run_eval_code_obj /__w/jax/jax/cpython/Python/pythonrun.c:1362:53 (python3.13+0x4a2ee6) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #1 run_mod /__w/jax/jax/cpython/Python/pythonrun.c:1466:19 (python3.13+0x4a26d5) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #2 _PyRun_StringFlagsWithName /__w/jax/jax/cpython/Python/pythonrun.c:1261:15 (python3.13+0x49fa64) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #3 PyRun_StringFlags /__w/jax/jax/cpython/Python/pythonrun.c:1273:12 (python3.13+0x49fa64) #4 builtin_exec_impl /__w/jax/jax/cpython/Python/bltinmodule.c (python3.13+0x3d99c2) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #5 builtin_exec /__w/jax/jax/cpython/Python/clinic/bltinmodule.c.h:556:20 (python3.13+0x3d99c2) #6 cfunction_vectorcall_FASTCALL_KEYWORDS /__w/jax/jax/cpython/Objects/methodobject.c:441:24 (python3.13+0x28a5d0) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #7 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1eb0ea) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #8 PyObject_Vectorcall /__w/jax/jax/cpython/Objects/call.c:327:12 (python3.13+0x1eb0ea) #9 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:813:23 (python3.13+0x3e385b) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #10 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.13+0x3df98a) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #11 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1814:12 (python3.13+0x3df98a) #12 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.13+0x1eb75f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #13 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1ef7e0) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #14 method_vectorcall /__w/jax/jax/cpython/Objects/classobject.c:92:18 (python3.13+0x1ef7e0) #15 _PyVectorcall_Call /__w/jax/jax/cpython/Objects/call.c:273:16 (python3.13+0x1eb3d3) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #16 _PyObject_Call /__w/jax/jax/cpython/Objects/call.c:348:16 (python3.13+0x1eb3d3) #17 PyObject_Call /__w/jax/jax/cpython/Objects/call.c:373:12 (python3.13+0x1eb455) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #18 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:1355:26 (python3.13+0x3e5a42) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #19 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.13+0x3df98a) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #20 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1814:12 (python3.13+0x3df98a) #21 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.13+0x1eb75f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #22 _PyObject_VectorcallDictTstate /__w/jax/jax/cpython/Objects/call.c:135:15 (python3.13+0x1ea2dd) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #23 _PyObject_Call_Prepend /__w/jax/jax/cpython/Objects/call.c:504:24 (python3.13+0x1ebdd7) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #24 slot_tp_call /__w/jax/jax/cpython/Objects/typeobject.c:9556:15 (python3.13+0x2f9718) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #25 _PyObject_MakeTpCall /__w/jax/jax/cpython/Objects/call.c:242:18 (python3.13+0x1ea54c) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #26 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:166:16 (python3.13+0x1eb1a8) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #27 PyObject_Vectorcall /__w/jax/jax/cpython/Objects/call.c:327:12 (python3.13+0x1eb1a8) #28 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:813:23 (python3.13+0x3e385b) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #29 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.13+0x3df98a) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #30 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1814:12 (python3.13+0x3df98a) #31 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.13+0x1eb75f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #32 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1ef72f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #33 method_vectorcall /__w/jax/jax/cpython/Objects/classobject.c:70:20 (python3.13+0x1ef72f) #34 _PyVectorcall_Call /__w/jax/jax/cpython/Objects/call.c:273:16 (python3.13+0x1eb3d3) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #35 _PyObject_Call /__w/jax/jax/cpython/Objects/call.c:348:16 (python3.13+0x1eb3d3) #36 PyObject_Call /__w/jax/jax/cpython/Objects/call.c:373:12 (python3.13+0x1eb455) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #37 thread_run /__w/jax/jax/cpython/./Modules/_threadmodule.c:337:21 (python3.13+0x568202) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #38 pythread_wrapper /__w/jax/jax/cpython/Python/thread_pthread.h:243:5 (python3.13+0x4c1107) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) Previous write of size 4 at 0x567f47699168 by thread T7 (mutexes: read M0): #0 run_eval_code_obj /__w/jax/jax/cpython/Python/pythonrun.c:1362:53 (python3.13+0x4a2ee6) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #1 run_mod /__w/jax/jax/cpython/Python/pythonrun.c:1466:19 (python3.13+0x4a26d5) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #2 _PyRun_StringFlagsWithName /__w/jax/jax/cpython/Python/pythonrun.c:1261:15 (python3.13+0x49fa64) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #3 PyRun_StringFlags /__w/jax/jax/cpython/Python/pythonrun.c:1273:12 (python3.13+0x49fa64) #4 builtin_exec_impl /__w/jax/jax/cpython/Python/bltinmodule.c (python3.13+0x3d99c2) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #5 builtin_exec /__w/jax/jax/cpython/Python/clinic/bltinmodule.c.h:556:20 (python3.13+0x3d99c2) #6 cfunction_vectorcall_FASTCALL_KEYWORDS /__w/jax/jax/cpython/Objects/methodobject.c:441:24 (python3.13+0x28a5d0) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #7 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1eb0ea) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #8 PyObject_Vectorcall /__w/jax/jax/cpython/Objects/call.c:327:12 (python3.13+0x1eb0ea) #9 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:813:23 (python3.13+0x3e385b) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #10 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.13+0x3df98a) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #11 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1814:12 (python3.13+0x3df98a) #12 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.13+0x1eb75f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #13 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1ef7e0) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #14 method_vectorcall /__w/jax/jax/cpython/Objects/classobject.c:92:18 (python3.13+0x1ef7e0) #15 _PyVectorcall_Call /__w/jax/jax/cpython/Objects/call.c:273:16 (python3.13+0x1eb3d3) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #16 _PyObject_Call /__w/jax/jax/cpython/Objects/call.c:348:16 (python3.13+0x1eb3d3) #17 PyObject_Call /__w/jax/jax/cpython/Objects/call.c:373:12 (python3.13+0x1eb455) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #18 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:1355:26 (python3.13+0x3e5a42) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #19 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.13+0x3df98a) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #20 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1814:12 (python3.13+0x3df98a) #21 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.13+0x1eb75f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #22 _PyObject_VectorcallDictTstate /__w/jax/jax/cpython/Objects/call.c:135:15 (python3.13+0x1ea2dd) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #23 _PyObject_Call_Prepend /__w/jax/jax/cpython/Objects/call.c:504:24 (python3.13+0x1ebdd7) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #24 slot_tp_call /__w/jax/jax/cpython/Objects/typeobject.c:9556:15 (python3.13+0x2f9718) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #25 _PyObject_MakeTpCall /__w/jax/jax/cpython/Objects/call.c:242:18 (python3.13+0x1ea54c) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #26 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:166:16 (python3.13+0x1eb1a8) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #27 PyObject_Vectorcall /__w/jax/jax/cpython/Objects/call.c:327:12 (python3.13+0x1eb1a8) #28 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:813:23 (python3.13+0x3e385b) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #29 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.13+0x3df98a) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #30 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1814:12 (python3.13+0x3df98a) #31 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.13+0x1eb75f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #32 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:168:11 (python3.13+0x1ef72f) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #33 method_vectorcall /__w/jax/jax/cpython/Objects/classobject.c:70:20 (python3.13+0x1ef72f) #34 _PyVectorcall_Call /__w/jax/jax/cpython/Objects/call.c:273:16 (python3.13+0x1eb3d3) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #35 _PyObject_Call /__w/jax/jax/cpython/Objects/call.c:348:16 (python3.13+0x1eb3d3) #36 PyObject_Call /__w/jax/jax/cpython/Objects/call.c:373:12 (python3.13+0x1eb455) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #37 thread_run /__w/jax/jax/cpython/./Modules/_threadmodule.c:337:21 (python3.13+0x568202) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8) #38 pythread_wrapper /__w/jax/jax/cpython/Python/thread_pthread.h:243:5 (python3.13+0x4c1107) (BuildId: d6d54de3753b7c6777cd2a5c08fbef6663ab66e8)The PR was merged into main, but I didn't backport it to 3.13. I've been generally hesitant to backport PRs that primarily fix TSAN warnings as opposed to crashes or other user visible misbehavior.
If it makes testing Jax easier, let me know and we can reconsider backporting the fix.
The PR was merged into main, but I didn't backport it to 3.13. I've been generally hesitant to backport PRs that primarily fix TSAN warnings as opposed to crashes or other user visible misbehavior.
If it makes testing Jax easier, let me know and we can reconsider backporting the fix.
It's not critical. It's just an entry in a tsan suppression file.
https://github.com/jax-ml/jax/blob/d3836f160cc6270280ba75c0ae5b12cf1b99535f/.github/workflows/tsan-suppressions.txt#L27
I'm just trying to be aggressive in making sure that these issues get fixed upstream since I want 3.14 to be race free for us.Actually, we're doing pretty well overall. We're down to only 2 unfixed races in our test suite (#129748, #128050), assuming the things tagged as fixed in 3.14 are indeed fixed.
Are you able to test with 3.14 as well? If not, what are the blockers?
Are you able to test with 3.14 as well? If not, what are the blockers?
No blockers. We just don't have that test. We've done it manually a few times. Let me add that to our CI.
Closing, we haven't seen this race under 3.14.
Bug report
Bug description:
Run the following code under Python 3.13.1t with thread-sanitizer enabled:
Get:
I think
namedtuplecallseval(), which triggers a race here:cpython/Python/pythonrun.c
Line 1318 in 0671451
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs