Conversation
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.
On shutdown, each worker puts its pid on the result queue before exiting,
while the executor manager thread waits for the workers in
_join_executor_internals()without reading that queue.If the result pipe fills up, for example because Linux shrank it under
fs.pipe-user-pages-softon a machine with many workers,an exiting worker blocks forever writing to it while holding the queue's write lock.
Every other worker then blocks behind it, and
shutdown(wait=True)never returns.This change drains the result queue while joining each worker.
When
_join_executor_internals()is reached there are no pending work items,so the only messages left are worker exit notifications and they can be discarded.
The new test makes the hang deterministic with two workers.
Right before the workers are told to exit, a thread puts a
PIPE_MAX_SIZEpayload on the result queue.This is to emulate the alot of workers exiting and writing their results back.
That thread blocks while holding the queue's write lock, so without the fix every exiting worker blocks behind it.
Testing:
./python -m test test_concurrent_futurespasses.without the fix it hangs.
Prepared with help from an AI assistant (Claude). I reviewed and verified the change.