]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] gh-112275: Fix HEAD_LOCK deadlock in child process after fork (GH-112336) ...
authorŁukasz Langa <lukasz@langa.pl>
Wed, 4 Sep 2024 20:41:03 +0000 (22:41 +0200)
committerGitHub <noreply@github.com>
Wed, 4 Sep 2024 20:41:03 +0000 (22:41 +0200)
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 522799a05e3e820339718151ac055af6d864d463)

Co-authored-by: ChuBoning <102216855+ChuBoning@users.noreply.github.com>
Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst [new file with mode: 0644]
Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst
new file mode 100644 (file)
index 0000000..d663be1
--- /dev/null
@@ -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.
index 7645bcfea97b4f4e4fd6fba55109b2fc63690a3b..f498d40e34c3cf180fc24bef9557fde407b1f11a 100644 (file)
@@ -589,10 +589,10 @@ PyOS_AfterFork_Child(void)
 {
     _PyRuntimeState *runtime = &_PyRuntime;
     _PyGILState_Reinit(runtime);
+    _PyRuntimeState_ReInitThreads(runtime);
     _PyEval_ReInitThreads(runtime);
     _PyImport_ReInitLock();
     _PySignal_AfterFork();
-    _PyRuntimeState_ReInitThreads(runtime);
     _PyInterpreterState_DeleteExceptMain(runtime);
 
     run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);