Skip to content

Commit fa67e46

Browse files
committed
gh-153852: Assert thread list non-empty only after stopping the world
Move the threads.head assert in handle_thread_shutdown_exception to after _PyEval_StopTheWorld so it does not race tstate_delete_common (TSAN-0034).
1 parent f5f5059 commit fa67e46

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a free-threading race in finalization by asserting the thread list is non-empty only after stopping the world.

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3827,8 +3827,8 @@ handle_thread_shutdown_exception(PyThreadState *tstate)
38273827
assert(tstate != NULL);
38283828
assert(_PyErr_Occurred(tstate));
38293829
PyInterpreterState *interp = tstate->interp;
3830-
assert(interp->threads.head != NULL);
38313830
_PyEval_StopTheWorld(interp);
3831+
assert(interp->threads.head != NULL); /* safe: world is stopped */
38323832

38333833
// We don't have to worry about locking this because the
38343834
// world is stopped.

0 commit comments

Comments
 (0)