Skip to content

Commit fa0dd0b

Browse files
committed
Fix a potential dead lock in add_to_pending_deletion_list
1 parent 6858161 commit fa0dd0b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Python/optimizer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,17 @@ add_to_pending_deletion_list(_PyExecutorObject *self)
296296
interp->executor_deletion_list_head = self;
297297
if (interp->executor_deletion_list_remaining_capacity > 0) {
298298
interp->executor_deletion_list_remaining_capacity--;
299+
EXECUTOR_LIST_UNLOCK(interp);
299300
}
300301
else {
302+
/* Release the lock before calling _Py_ClearExecutorDeletionList
303+
* to avoid deadlock, since it also tries to acquire the same lock */
304+
EXECUTOR_LIST_UNLOCK(interp);
301305
_Py_ClearExecutorDeletionList(interp);
306+
EXECUTOR_LIST_LOCK(interp);
307+
interp->executor_deletion_list_head = self;
308+
EXECUTOR_LIST_UNLOCK(interp);
302309
}
303-
EXECUTOR_LIST_UNLOCK(interp);
304310
}
305311

306312
static void

0 commit comments

Comments
 (0)