https://github.com/python/cpython/commit/d3f39cefe721db643957d48316ac98c5e279f0c3 commit: d3f39cefe721db643957d48316ac98c5e279f0c3 branch: 3.10 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: ambv <luk...@langa.pl> date: 2024-09-04T19:26:29+02:00 summary:
[3.10] gh-112275: Fix HEAD_LOCK deadlock in child process after fork (GH-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 522799a05e3e820339718151ac055af6d864d463) Co-authored-by: ChuBoning <102216855+chubon...@users.noreply.github.com> Co-authored-by: Ćukasz Langa <luk...@langa.pl> files: A Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst M 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 index 00000000000000..d663be1867ed3d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst @@ -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. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 43e69fc322b595..feffa43cfd0de4 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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); @@ -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; _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com