Skip to content

Commit

Permalink
[3.10] 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) (#123687)

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 <102216855+ChuBoning@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent 2e861ac commit d3f39ce
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 d3f39ce

Please sign in to comment.