Repository navigation
Keep LocalExecutor running when a worker dies holding the queue read lock - #74588
Open
anmolxlight wants to merge 11 commits into
Open
anmolxlight wants to merge 11 commits into
anmolxlight wants to merge 11 commits into
Conversation
anmolxlight
requested review from
XD-DENG,
ashb,
dheerajturaga,
hussein-awala,
o-nikolas and
pierrejeambrun
as code owners
October 12, 2026 12:15
…lock Signed-off-by: anmolxlight <anmolxlight@gmail.com>
Signed-off-by: anmolxlight <anmolxlight@gmail.com>
…i_transport_lifecycle thread-liveness assert; no code change)
…rmination (no code change)
anmolxlight
force-pushed
the
fix-74575-localexecutor-dead-worker-lock
branch
from
October 14, 2026 15:56
f882c6f to
76d11de
Compare
…ce hit job-timeout (no code change)
The test dispatched workloads before registering its fake worker, so _process_workloads spawned a real worker that never got a poison pill. That non-daemon child kept pytest from exiting, which timed out the Core DB test jobs. Signed-off-by: anmolxlight <anmolxlight@gmail.com>
o-nikolas
reviewed
Oct 23, 2026
o-nikolas
left a comment
Contributor
There was a problem hiding this comment.
Thanks, a few things before this can go in:
- This now conflicts with #70545 on main.
_pick_workeralready drains results before eachput, so its extra_read_results()line can go, but its two tests useactivity_queue/_unread_messagesand need porting. - Please drop
74588.bugfix.rst. Core only takessignificantnewsfragments now (see contributing-docs/18_contribution_workflow.rst). - When can the
_pick_workerfallback (next(iter(self.workers))) actually happen? If it's real, the workload waits behind a possibly long task, and if that worker dies it sits untiltask_queued_timeout. If it's only defensive, a warning log would help. Also please drop theponytail:prefix. - In fork mode, replacement workers are now forked without
gc.freeze; the old_check_workersrefill used_spawn_workers_with_gc_freeze. Worth keeping? - Could you add unit tests for the
_pick_workerbranches (idle reuse, spawn under parallelism, fallback) and the new late-result branch in_read_results?test_executor_lazy_worker_spawningalso lost its spawn-on-dispatch check.
Not for this PR:result_queueis still shared, so a worker killed mid-putholds its write lock the same way. Small window, but maybe worth a follow-up issue.
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74575.
Problem
LocalExecutorgave all workers oneSimpleQueueas their input. In CPython,SimpleQueue.get()holds a shared read lock while it blocks on the pipe. If the idle worker holding that lock is SIGKILLed (for example by the OOM killer), nothing releases the lock. Every other worker then waits on it forever, and the executor keeps accepting work it can never run. Tasks stayqueuedwhile the scheduler reports healthy.Fix
Give each worker its own input queue and dispatch each workload to a specific worker:
_dispatchpicks an idle worker, spawns one underparallelism, or queues behind a busy one._dispatched), so a worker that dies before START still leaves the key for the scheduler's stuck-in-queued revoke, as before.running, so a worker is not left excluded.Tests
test_workload_runs_after_worker_holding_read_lock_is_killed: kills all idle workers, then requires a later task to succeed. Onmainit fails with the symptom from the issue (task never leaves the queue, 30s timeout). With this fix it passes (~3.6s).test_local_executor_check_workers.pyfor the new reap contract.test_local_executor.pyandtest_local_executor_check_workers.py: 65 passed, 1 skipped.test_base_executor.pyhas 3test_debug_dump*errors that also occur on unmodifiedmain; unrelated.ruff check,ruff format --check, andmypyonlocal_executor.pyare clean.Notes
This does not change behavior when workers stay alive. The per-worker queue is also what makes a killed worker harmless to the rest of the pool.