Repository navigation
Gracefully drain workers on shutdown instead of terminating them - #387
Open
artem-sitd wants to merge 1 commit into
Open
artem-sitd wants to merge 1 commit into
artem-sitd wants to merge 1 commit into
Conversation
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.
Fix #386.
Problem
With
--workers > 1, SIGTERM/SIGINT torn down in-flight requests:shutdown_eventis set;wait(process.sentinel ...), which returns as soon as any worker exits;activeisFalse) and the master callsprocess.terminate()on the remaining, busy workers.The result is that requests still being served are cut off ("Empty reply from server"), even when
-w 1serves them fine.Change
Replace the
terminate()loop with_drain(processes), which joins the remaining workers so they can finish their own graceful shutdown (bounded on the worker side byconfig.graceful_timeout). This matches the single-worker behaviour and mirrors the existing unboundedprocess.join()in the reload handler.Tests
Added
tests/test_run.pyasserting the master joins workers and never terminates them. Existingtest_utils.pyandtest_config.pypass.Note: on Python 3.12+, worker-side draining can be effectively unbounded because of
Server.wait_closed()(#308); that is a separate issue and its fix would letconfig.graceful_timeout(or a future hard cap in the master) be applied without cutting in-flight requests.