Repository navigation
fix(parse): pool and timeout workers exit when their parent dies - #487
Merged
HananKavitzAmat merged 1 commit intoNov 8, 2026
Merged
Conversation
A ProcessPoolExecutor worker blocks on its call queue, whose pipe it holds both ends of, so it never notices its parent dying. A killed ChunkHound process left every parse worker running, each holding hundreds of MB of commit, until killed by hand. Every multiprocessing child already has a sentinel for its parent (multiprocessing.parent_process()): a process handle on Windows, a pipe on POSIX. exit_when_parent_dies() waits on it from a daemon thread and exits the process when the parent is gone. It is the initializer of the parse pool and of both indexing_coordinator pools, and the first call in both per-file timeout children. A Windows job object with KILL_ON_JOB_CLOSE was the alternative: it is Windows-only (the same orphaning happens on POSIX), and each worker would have to be assigned to the job after ProcessPoolExecutor spawns it, which the executor gives no hook for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
Looks good! Thanks |
fstrasz
added a commit
to fstrasz/chunkhound
that referenced
this pull request
Nov 11, 2026
One conflict, in chunkhound/pipeline_bridge.py _get_parse_pool: chunkhound#487 on main added initializer=exit_when_parent_dies to the same ProcessPoolExecutor call this branch gave mp_context=multiprocessing.get_context("spawn"). Kept both arguments and this branch's comment. exit_when_parent_dies is a module-level function, so it pickles under spawn. Both arguments are load-bearing: without mp_context, test_parse_pool_is_created_with_a_spawn_context fails; without the initializer, chunkhound#487's test_parse_pool_worker_exits_when_parent_is_killed fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
A
ProcessPoolExecutorworker waits on its call queue, and the queue is pickled into the worker with both pipe ends, so the worker never sees the pipe close when its parent dies. When a ChunkHound process exits abnormally (killed MCP server, crashed daemon,TerminateProcess, SIGKILL), every parse worker it started keeps running until someone kills it. On Windows each one held 35-370 MB of commit in our measurements, and they accumulate across killed sessions.Fix
chunkhound/utils/parent_watch.pyaddsexit_when_parent_dies(). Every multiprocessing child already has a sentinel for its parent inmultiprocessing.parent_process()(a process handle on Windows, a pipe on POSIX). A daemon thread waits on it and callsos._exit(1)when the parent is gone.It is wired in as:
initializerof the parse pool (pipeline_bridge._get_parse_pool);initializerof bothProcessPoolExecutors inindexing_coordinator;pipeline_bridge._parse_file_worker_for_timeout,batch_processor._parse_file_worker), so a timeout child of a dying worker goes too.Alternative considered: a Windows job object with
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSERejected because it is Windows-only while the orphaning happens on every platform, and because
ProcessPoolExecutorspawns workers lazily with no hook to assign each one to a job after it starts.Test
tests/contracts/test_parse_pool_parent_death.pystarts the real parse pool in a child Python process, has it spawn a worker, hard-kills that parent, and asserts the worker exits within 20 s.Related tests (contracts, batch processor timeout, coordinator, root indexing, skip-unchanged, pipeline bridge config, unknown files) run serially on Windows: 162 passed, 5 skipped.
🤖 Generated with Claude Code