mirror of https://github.com/python/cpython.git
[3.9] GH-102126: fix deadlock at shutdown when clearing thread states (GH-102222) (#102236)
(cherry picked from commit 5f11478ce7
)
This commit is contained in:
parent
b5a94301a2
commit
7cb3a44747
|
@ -0,0 +1 @@
|
|||
Fix deadlock at shutdown when clearing thread states if any finalizer tries to acquire the runtime head lock. Patch by Kumar Aditya.
|
|
@ -288,11 +288,19 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
|
|||
_PyErr_Clear(tstate);
|
||||
}
|
||||
|
||||
// Clear the current/main thread state last.
|
||||
HEAD_LOCK(runtime);
|
||||
for (PyThreadState *p = interp->tstate_head; p != NULL; p = p->next) {
|
||||
PyThreadState_Clear(p);
|
||||
}
|
||||
PyThreadState *p = interp->tstate_head;
|
||||
HEAD_UNLOCK(runtime);
|
||||
while (p != NULL) {
|
||||
// See https://github.com/python/cpython/issues/102126
|
||||
// Must be called without HEAD_LOCK held as it can deadlock
|
||||
// if any finalizer tries to acquire that lock.
|
||||
PyThreadState_Clear(p);
|
||||
HEAD_LOCK(runtime);
|
||||
p = p->next;
|
||||
HEAD_UNLOCK(runtime);
|
||||
}
|
||||
|
||||
Py_CLEAR(interp->audit_hooks);
|
||||
|
||||
|
|
Loading…
Reference in New Issue