Add proper subprocess cleanup on application shutdown#46
Open
SerGem811 wants to merge 1 commit intochutesai:mainfrom
Open
Add proper subprocess cleanup on application shutdown#46SerGem811 wants to merge 1 commit intochutesai:mainfrom
SerGem811 wants to merge 1 commit intochutesai:mainfrom
Conversation
Author
|
Hi @jondurbin |
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: Add Proper Subprocess Cleanup on Application Shutdown
Why This Is Important
When running in Docker containers, subprocesses (SGLang, vLLM, SSH server) spawned by the application were not being properly cleaned up on shutdown, leading to several critical issues:
Docker sends
SIGTERMsignals when stopping containers. Without proper cleanup handlers, subprocesses continue running, causing resource leaks and potential conflicts when containers are restarted or scaled.What Is Fixed
1. SGLang Subprocess Cleanup (
chutes/chute/template/sglang.py)@chute.on_event("shutdown")hook to gracefully terminate SGLang subprocess2. vLLM Subprocess Cleanup (
chutes/chute/template/vllm.py)@chute.on_event("shutdown")hook to gracefully terminate vLLM subprocess3. vLLM Embedding Subprocess Cleanup (
chutes/chute/template/embedding.py)4. SSH Process Reference Return (
chutes/entrypoint/ssh.py)setup_ssh_access()function to return the SSH subprocess referenceTechnical Details
@chute.on_event("shutdown")decorator to register cleanup handlersterminate()first, waits up to 5 seconds for graceful shutdownkill()to force terminationFiles Changed
Code Changes Summary
sglang.py
import subprocessat module levelcleanup_sglang()method with@chute.on_event("shutdown")decoratorvllm.py
cleanup_vllm()method with@chute.on_event("shutdown")decoratorembedding.py
cleanup_vllm()method with@chute.on_event("shutdown")decoratorssh.py
setup_ssh_access()to returnsshd_processreferenceImpact