Skip to content

Commit

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

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]>
Co-authored-by: Łukasz Langa <[email protected]>
  • Loading branch information
2 people authored and miss-islington committed Sep 4, 2024
1 parent 2e861ac commit bbeaba7
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 @@ -598,6 +598,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 @@ -613,11 +618,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 bbeaba7

Please sign in to comment.