feat: graceful SIGTERM/SIGINT worker drain (finish in-flight task before exit)#14
Open
adhikjoshi wants to merge 1 commit into
Open
feat: graceful SIGTERM/SIGINT worker drain (finish in-flight task before exit)#14adhikjoshi wants to merge 1 commit into
adhikjoshi wants to merge 1 commit into
Conversation
… before exit) Worker loops ran `while True` and ignored the shutdown flag, and the threads are daemons — so on SIGTERM the process exited and killed them mid-task, orphaning the in-flight task (and losing its result if the task handler uploaded synchronously). Worker loops now run `while not self._shutdown_event.is_set()` and blpop with a 5s timeout so shutdown is noticed promptly. New ModelQ.shutdown() sets the event and joins the worker threads (up to a timeout), and the CLI calls it on SIGTERM/SIGINT so an in-flight task — and its upload — completes before the process exits.
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
run-workersregisters a SIGTERM handler that only sets a flag, but the worker loop runswhile Trueand never checks it, and the worker threads aredaemon=True. So on SIGTERM the process exits and kills them mid-task, orphaning the in-flight task (and losing its result when the task handler uploads synchronously). This is a root cause of serverless replicas being scaled down mid-generation and 404-ing their output.Change
while not self._shutdown_event.is_set()+blpop("ml_tasks", timeout=5)so shutdown is noticed within ~5s.ModelQ.shutdown(timeout=300): sets the event andjoin()s the worker threads so the current task finishes (and, for synchronous handlers, its upload completes) before exit.app_instance.shutdown()on SIGTERM/SIGINT.Existing behavior is unchanged during normal operation; only the shutdown path drains gracefully. Pairs with gpulab-v2 graceful
docker stopon scale-down and the flux-klein-server synchronous-upload fix.Version bump 1.0.14 → 1.0.15. Publishing the GitHub release triggers the PyPI publish (cd.yml).