Skip to content

Commit 0152431

Browse files
ambvChuBoning
andauthored
[3.9] gh-112275: Fix HEAD_LOCK deadlock in child process after fork (GH-112336) (#123688)
HEAD_LOCK is called from _PyEval_ReInitThreads->_PyThreadState_DeleteExcept before _PyRuntimeState_ReInitThreads reinit runtime->interpreters.mutex which might be locked before fork. (cherry picked from commit 522799a) Co-authored-by: ChuBoning <[email protected]>
1 parent 9290419 commit 0152431

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A deadlock involving ``pystate.c``'s ``HEAD_LOCK`` in ``posixmodule.c``
2+
at fork is now fixed. Patch by ChuBoning based on previous Python 3.12
3+
fix by Victor Stinner.

Modules/posixmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,10 @@ PyOS_AfterFork_Child(void)
589589
{
590590
_PyRuntimeState *runtime = &_PyRuntime;
591591
_PyGILState_Reinit(runtime);
592+
_PyRuntimeState_ReInitThreads(runtime);
592593
_PyEval_ReInitThreads(runtime);
593594
_PyImport_ReInitLock();
594595
_PySignal_AfterFork();
595-
_PyRuntimeState_ReInitThreads(runtime);
596596
_PyInterpreterState_DeleteExceptMain(runtime);
597597

598598
run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);

0 commit comments

Comments
 (0)