Repository navigation
Crash at finalization after fail to start new thread #109746
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
- addedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on Sep 22, 2023 Possible fix (the tests are green):
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 7692bacccc..071dc90a24 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1204,6 +1204,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) if (ident == PYTHREAD_INVALID_THREAD_ID) { PyErr_SetString(ThreadError, "can't start new thread"); PyThreadState_Clear(boot->tstate); + PyThreadState_Delete(boot->tstate); thread_bootstate_free(boot, 1); return NULL; } diff --git a/Python/pystate.c b/Python/pystate.c index dcc6c11221..983937202b 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1589,7 +1589,9 @@ tstate_delete_common(PyThreadState *tstate) if (tstate->_status.bound_gilstate) { unbind_gilstate_tstate(tstate); } - unbind_tstate(tstate); + if (tstate->_status.bound) { + unbind_tstate(tstate); + } // XXX Move to PyThreadState_Clear()? clear_datastack(tstate);
@ericsnowcurrently, is my analysis correct?
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.12only security fixesonly security fixes3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dir
on Sep 22, 2023 - changed the title
[-]Crash at finalization after fail to create new thread[/-][+]Crash at finalization after fail to start new thread[/+]on Sep 22, 2023 - added a commit that references this issue
on Nov 22, 2024 Thank you for your contribution @chgnrdv.
Reacted by chgnrdvSince this was merged to 3.13, the NoGIL buildbot is showing frequent failures in
test_threading: https://buildbot.python.org/#/builders/1396Closing since the fix of the fix was completed and backported.
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Crash report
What happened?
Bisected to e11fc03, but I guess this issue exists longer, and assertion that is added to
PyThreadState_Clearby this commit just made it visible.Error message with backtrace:
When trying to start a new thread, Python creates new thread state by
_PyThreadState_Newcall, adding this new state to list of thread states for current interpreter:cpython/Modules/_threadmodule.c
Line 1191 in c32abf1
If consequent call to
PyThread_start_new_threadfails, this new state gets cleared, but remains in list:cpython/Modules/_threadmodule.c
Lines 1203 to 1209 in c32abf1
Then, at Python finalization, call to
_PyThreadState_DeleteExceptattempts to clear this thread state again, which causes assertion failure:cpython/Python/pystate.c
Lines 1674 to 1682 in 3e8fcb7
cc @ericsnowcurrently
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.0a0 (heads/main:d4cea794a7, Sep 22 2023, 18:42:05) [GCC 10.2.1 20210110]
Linked PRs
_thread.start_new_threaddelete state of new thread on its startup failure #109761