Skip to content

Commit

Permalink
[3.11]GH-112275: Fix HEAD_LOCK deadlock in child process after fork (#…
Browse files Browse the repository at this point in the history
…112336)

HEAD_LOCK is called from _PyEval_ReInitThreads->_PyThreadState_DeleteExcept before _PyRuntimeState_ReInitThreads reinit runtime->interpreters.mutex which might be locked before fork.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
ChuBoning and ambv authored Sep 4, 2024
1 parent 851821d commit 522799a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A deadlock involving ``pystate.c``'s ``HEAD_LOCK`` in ``posixmodule.c``
at fork is now fixed. Patch by ChuBoning based on previous Python 3.12
fix by Victor Stinner.
10 changes: 5 additions & 5 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ PyOS_AfterFork_Child(void)
goto fatal_error;
}

status = _PyRuntimeState_ReInitThreads(runtime);
if (_PyStatus_EXCEPTION(status)) {
goto fatal_error;
}

PyThreadState *tstate = _PyThreadState_GET();
_Py_EnsureTstateNotNULL(tstate);

Expand All @@ -622,11 +627,6 @@ PyOS_AfterFork_Child(void)

_PySignal_AfterFork();

status = _PyRuntimeState_ReInitThreads(runtime);
if (_PyStatus_EXCEPTION(status)) {
goto fatal_error;
}

status = _PyInterpreterState_DeleteExceptMain(runtime);
if (_PyStatus_EXCEPTION(status)) {
goto fatal_error;
Expand Down

0 comments on commit 522799a

Please sign in to comment.