mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Provide a sanity check during PyThreadState_DeleteCurrent() and
PyThreadState_Delete() to avoid an infinite loop when the tstate list is messed up and has somehow becomes circular and does not contain the current thread. I don't know how this happens but it does, *very* rarely. On more than one hardware platform. I have not been able to reproduce it manually. Attaching to a process where its happening: it has always been in an infinite loop over a single element tstate list that is not the tstate we're looking to delete. It has been in t_bootstrap()'s call to PyThreadState_DeleteCurrent() as a pthread is exiting.
This commit is contained in:
parent
21297fa621
commit
2778c999e3
1 changed files with 10 additions and 0 deletions
|
@ -240,6 +240,7 @@ tstate_delete_common(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp;
|
PyInterpreterState *interp;
|
||||||
PyThreadState **p;
|
PyThreadState **p;
|
||||||
|
PyThreadState *prev_p = NULL;
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
Py_FatalError("PyThreadState_Delete: NULL tstate");
|
Py_FatalError("PyThreadState_Delete: NULL tstate");
|
||||||
interp = tstate->interp;
|
interp = tstate->interp;
|
||||||
|
@ -252,6 +253,15 @@ tstate_delete_common(PyThreadState *tstate)
|
||||||
"PyThreadState_Delete: invalid tstate");
|
"PyThreadState_Delete: invalid tstate");
|
||||||
if (*p == tstate)
|
if (*p == tstate)
|
||||||
break;
|
break;
|
||||||
|
if (*p == prev_p)
|
||||||
|
Py_FatalError(
|
||||||
|
"PyThreadState_Delete: small circular list(!)"
|
||||||
|
" and tstate not found.");
|
||||||
|
prev_p = *p;
|
||||||
|
if ((*p)->next == interp->tstate_head)
|
||||||
|
Py_FatalError(
|
||||||
|
"PyThreadState_Delete: circular list(!) and"
|
||||||
|
" tstate not found.");
|
||||||
}
|
}
|
||||||
*p = tstate->next;
|
*p = tstate->next;
|
||||||
HEAD_UNLOCK();
|
HEAD_UNLOCK();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue