Scenario
A rolling update that dropped every running answer
RolesInference EngineeringCustomer AI DeploymentAI Evaluation and Reliability
- Engine
- SGLang 0.5.22 on its MLX path
- Model
- mlx-community/Qwen3-0.6B-4bit
- Hardware
- one laptop with unified memory, which captures no CUDA graphs
Situation
A platform team deploys SGLang pods with a rolling update. The container starts the server through a small wrapper script. When the orchestrator asks the pod to stop, the wrapper forwards the signal it receives to its whole process group. Every deploy produces a burst of failed requests. The users who were in the middle of an answer get a broken stream, and the pod log of each stopped server reports a crash, although nothing was wrong with the model.
The on-call engineer reads the end of one log and finds the crash in it. The team has two proposals: raise the grace period for termination from 30 s to five minutes, and add a retry in the gateway for the broken streams. You review the evidence before either change ships.
Questions
- The log says that a subprocess crashed with exit code -15. What is that exit code, and who sent it?
- Read the drain description. Which process must receive the signal, and what happens to the health endpoint while the drain runs?
- The second capture sends the signal to one process while a request runs. Trace the request from the signal to the exit code.
- A longer grace period was proposed. What decides the right value, and why does the output cap come first?
- Name the two ways a server skips the drain, and the environment variable trap at this version.
Commit to a cause after each listing. Write it down before you read the next one.
Evidence
the end of a stopped server's log, as the team read it
The scheduler child died with exit code -15 before the parent could drain, so the parent took the crash path and killed the tree.
[2026-10-16 14:01:45] SIGTERM received. signum=None frame=None. Draining requests and shutting down...
[2026-10-16 14:01:45] Subprocess scheduler_0 (pid=5909) crashed with exit code -15. Triggering SIGQUIT for cleanup...
[2026-10-16 14:01:45] SIGQUIT received. signum=None, frame=None. It usually means one child failed.
[2026-10-16 14:01:46] Sleeping 5 seconds before crash diagnostics to let GPU activity settle.
[2026-10-16 14:01:51] No live scheduler processes found; skipping py-spy and CUDA coredump.
[2026-10-16 14:01:51] kill_process_tree called: parent_pid=5782, include_parent=True, pid=5782Source: manuals/sglang-101/capture/out/server-default.log, lines 565-570
what the server does on a SIGTERM to its main process
Read the flag, the two timers and the order of the steps.
On SIGTERM, the HTTP server sets `gracefully_exit`, and `/health` starts to return 503. A watchdog in the tokenizer manager checks the flag every 5 s {{code}}. It then logs the remaining requests every 5 s until none remain. Then it sends `ShutdownReq` to the schedulers and gives them 15 s to exit before it kills them. [Figure 7.1](#fig-7-1) shows this path and the two paths that skip the drain.Source: manuals/sglang-101/sections/7-1-operating-sglang.md, lines 98-98
a SIGTERM to the main process only, with one request running
The decode batches continue after the signal, and the health check returns 503 during the drain.
[2026-10-16 14:13:54] SIGTERM received. signum=None frame=None. Draining requests and shutting down...
[2026-10-16 14:13:54] Decode batch, #running-req: 1, #token: 8, token usage: 0.00, cuda graph: False, gen throughput (token/s): 155.12, #queue-req: 0
[2026-10-16 14:13:54] Decode batch, #running-req: 1, #token: 8, token usage: 0.00, cuda graph: False, gen throughput (token/s): 161.61, #queue-req: 0
[2026-10-16 14:13:54] Decode batch, #running-req: 1, #token: 8, token usage: 0.00, cuda graph: False, gen throughput (token/s): 182.29, #queue-req: 0
[2026-10-16 14:13:54] Decode batch, #running-req: 1, #token: 8, token usage: 0.00, cuda graph: False, gen throughput (token/s): 204.07, #queue-req: 0
[2026-10-16 14:13:55] Decode batch, #running-req: 1, #token: 8, token usage: 0.00, cuda graph: False, gen throughput (token/s): 214.83, #queue-req: 0
[2026-10-16 14:13:55] Health check request received during shutdown. Returning 503.
[2026-10-16 14:13:55] INFO: 127.0.0.1:53237 - "GET /health HTTP/1.1" 503 Service UnavailableSource: manuals/sglang-101/capture/out/shutdown-exploratory.log, lines 120-127
the request completes and the server exits
The in-flight request returns 200, the remaining count reaches 0, and the server process finishes.
[2026-10-16 14:14:04] INFO: 127.0.0.1:53209 - "POST /generate HTTP/1.1" 200 OK
[2026-10-16 14:14:07] Gracefully exiting... Remaining number of requests 0. Remaining requests remaining_rids=[].
[2026-10-16 14:14:07] kill_process_tree called: parent_pid=53853, include_parent=False, pid=53853
[2026-10-16 14:14:07] INFO: Shutting down
[2026-10-16 14:14:07] INFO: Waiting for application shutdown.
[2026-10-16 14:14:07] INFO: Application shutdown complete.
[2026-10-16 14:14:07] INFO: Finished server process [53853]Source: manuals/sglang-101/capture/out/shutdown-exploratory.log, lines 176-182
what the client saw across the drain
The request for 3000 tokens finished, and the exit code was 0.
health before SIGTERM: 200
sent SIGTERM to the server process only
health during drain: 503
in-flight request: {"status": 200, "completion_tokens": 3000, "finish_reason": {"type": "length", "length": 3000}, "seconds": 14.2}
server exit code: 0Source: manuals/sglang-101/capture/out/shutdown-exploratory.txt
the two exits that skip the drain, and the grace period rule
Read which variable name the watchdog reads at 0.5.22, then the rule for the grace period.
The code has two exits that skip the drain. If the server is already `UnHealthy`, the watchdog exits at once. It also exits at once if the environment variable `SGL_FORCE_SHUTDOWN` is true. At v0.5.22 the watchdog reads that old name directly {{code}}.
The environment module declares the new name `SGLANG_FORCE_SHUTDOWN`. Its compatibility code copies `SGL_` variables to `SGLANG_` names, never the other way. **The code shows** that setting only `SGLANG_FORCE_SHUTDOWN` does not reach the watchdog. We read this in the code and did not run it, so we call it a likely bug. If you need a forced stop, set `SGL_FORCE_SHUTDOWN=1`.
**Our position:** set the termination grace period longer than your longest request at your output cap. A 32K-token answer at 30 tokens per second needs more than 18 minutes. Cap `max_tokens` before you set the grace period, or a drain can never finish in time.Source: manuals/sglang-101/sections/7-1-operating-sglang.md, lines 157-161
The answer
Show the walkthrough
- Read the exit code. A negative exit code is a signal number, and 15 is SIGTERM. In the first listing the parent logs that it received SIGTERM and starts to drain, and in the same second its scheduler child dies of the same signal. Two processes do not receive one signal at the same instant unless the sender addressed the group. The wrapper did that. The scheduler died first, the parent found a dead child, took the crash path, slept 5 seconds for diagnostics and killed the tree. Every running request died with the scheduler. The crash in the log is the symptom of the wrapper, not a fault in the server.
- Read who owns the drain. The manual describes the path. On SIGTERM the HTTP server sets
gracefully_exit, and/healthbegins to answer 503. A watchdog in the tokenizer manager checks the flag every 5 s and logs the remaining requests every 5 s until none remain. Then it sendsShutdownReqto the schedulers and gives them 15 s to exit before it kills them. The drain lives in the main process. A scheduler that gets the signal itself never gets the shutdown request, so the drain cannot begin. - Read the clean stop. In the second capture, the probe sent SIGTERM to the server process alone while one request for 3000 tokens ran. The decode batches continue after the signal line, and one second later the log says that a health check arrived during shutdown and returned 503. That 503 is what the orchestrator needs: stop sending traffic here, the pod is on its way out. Ten seconds later the request returns 200, the watchdog logs zero remaining requests, and the server process finishes.
- Read what the client saw. Health 200 before the signal, 503 during the drain, the request complete with all 3000 tokens and the finish reason
lengthafter 14.2 s, and an exit code of 0. Nothing was lost, and the server was gone about thirteen seconds after the signal. - Read the two exits that skip the drain. A server that is already
UnHealthyexits at once, and so does a server withSGL_FORCE_SHUTDOWNset. The environment module declares the new nameSGLANG_FORCE_SHUTDOWN, and its compatibility code copies old names to new names only, so the watchdog at this version still reads the old name. Setting only the new name does nothing. The manual read this in the code, did not run it, and calls it a likely bug. The same listing gives the rule for the grace period: longer than one request at the output cap, and a 32K-token answer at 30 tokens per second needs more than 18 minutes.
Show the resolution
The wrapper was the incident. It turned one SIGTERM into a signal for every process, the scheduler died before the parent could drain, and the parent reported a crash it did not cause. The fix is to make sglang serve the main process of the container, with exec in the script or as the entrypoint, so that the orchestrator's signal reaches the server alone. The capture is the proof: with the signal sent to one process, the request for 3000 tokens finished, /health returned 503 during the drain, and the exit code was 0.
Then size the stop. Cap max_tokens first, and set the grace period longer than one request at that cap. A five-minute grace period with no output cap still cuts every answer that runs longer than five minutes. For a forced stop in a test environment, set SGL_FORCE_SHUTDOWN=1, never only the new name. The gateway retry stays out: a drain finishes the answer on the pod that holds its cache, and a retry starts the answer again from its first token on another pod.
Show the wrong turns
“Raise the grace period to five minutes.”
The signal reached the scheduler child directly, so the drain never began. No grace period helps a drain that does not start, and a grace period shorter than one answer at the output cap still cuts answers.
“Retry the broken streams at the gateway.”
A retry pays for the prompt and the generated tokens a second time on another pod. The drain finishes the answer where it runs.
“Set SGLANG_FORCE_SHUTDOWN=1 for a fast stop in staging.”
At this version the watchdog reads SGL_FORCE_SHUTDOWN, so the new name does nothing, and a forced stop skips the drain, which is the incident.
“The scheduler crashed, so file a bug against the engine.”
Exit code -15 is a signal, not a fault. The log says who died first and who sent the signal.
Show the general rule
A graceful stop is a protocol between one sender and one receiver. Know which process holds the drain, make sure only that process gets the signal, and size the time you give it from the longest work you allow. Then test the stop with a request in flight and read the exit code, because a stop that works on an idle server proves nothing.
Taught in
The SGLang manual records both stops and the variable name trap in the shutdown part of the operating page, and the SRE for AI lesson gives the runbook shape that turns this reading into a repeatable check.