-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash at finalization after fail to start new thread #109746
Labels
3.12
bugs and security fixes
3.13
bugs and security fixes
extension-modules
C modules in the Modules dir
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-crash
A hard crash of the interpreter, possibly with a core dump
Comments
|
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? |
serhiy-storchaka
added a commit
that referenced
this issue
Nov 22, 2024
…n its startup failure (GH-109761) If Python fails to start newly created thread due to failure of underlying PyThread_start_new_thread() call, its state should be removed from interpreter' thread states list to avoid its double cleanup. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Nov 22, 2024
… new thread on its startup failure (pythonGH-109761) If Python fails to start newly created thread due to failure of underlying PyThread_start_new_thread() call, its state should be removed from interpreter' thread states list to avoid its double cleanup. (cherry picked from commit ca3ea9a) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Nov 22, 2024
… new thread on its startup failure (pythonGH-109761) If Python fails to start newly created thread due to failure of underlying PyThread_start_new_thread() call, its state should be removed from interpreter' thread states list to avoid its double cleanup. (cherry picked from commit ca3ea9a) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
Thank you for your contribution @chgnrdv. |
serhiy-storchaka
added a commit
that referenced
this issue
Nov 22, 2024
…hread on its startup failure (GH-109761) (GH-127171) If Python fails to start newly created thread due to failure of underlying PyThread_start_new_thread() call, its state should be removed from interpreter' thread states list to avoid its double cleanup. (cherry picked from commit ca3ea9a) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
serhiy-storchaka
added a commit
that referenced
this issue
Nov 22, 2024
…hread on its startup failure (GH-109761) (GH-127173) If Python fails to start newly created thread due to failure of underlying PyThread_start_new_thread() call, its state should be removed from interpreter' thread states list to avoid its double cleanup. (cherry picked from commit ca3ea9a) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
|
Since this was merged to 3.13, the NoGIL buildbot is showing frequent failures in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.12
bugs and security fixes
3.13
bugs and security fixes
extension-modules
C modules in the Modules dir
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-crash
A 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 #109761The text was updated successfully, but these errors were encountered: