Repository navigation
[Fix] Prevent zombie requests after client disconnect: abort pending requests before dropping tokenizer state - #35936
gencer-altan wants to merge 2 commits into
Conversation
|
Hi! Quick status on CI: all 16 failing checks fail at the Context while CI is pending: this change was verified on real AMD MI300X (ROCm) hardware with Qwen3.8-27B (TP=1, FP8 E4M3 KV cache) - after a client disconnect mid-decode, the orphaned request now gets an |
|
@Cayrop Before this fix, cancelled requests were still lingering as zombies. I have applied the PR to guqiong96/Lsglang@a7fee3c, and it runs well. Thanks again! |
chilltongx
left a comment
There was a problem hiding this comment.
The disconnect cleanup is directionally correct, but removing the rid_to_state guard from the public TokenizerManager.abort_request path makes the stated "unknown rids are a safe no-op" invariant false.
I verified this against the exact head a02bd281ba702d359dcb8ca9b08ecffbe78ad3dc. With tokenizer_worker_num == 1 and an empty rid_to_state, the base commit dispatches zero messages for abort_request(rid="batch"); this head dispatches one AbortReq. The scheduler then uses req.rid.startswith(recv_req.rid) at eight abort sites. Given active IDs batch_0, batch_1, and batch_10, an unknown/stale abort ID batch matches all three, and batch_1 also matches both batch_1 and batch_10. Batch IDs are generated with exactly this prefix scheme in GenerateReqInput._normalize_rid.
That changes /abort_request and the gRPC abort API from an exact-state-gated operation into a potentially broad prefix cancellation operation. The endpoint describes its argument as a request ID, not an arbitrary group prefix, so a stale or mistyped ID can now cancel unrelated live work sharing that prefix.
The zombie-request fix itself does not require this public-path change: _abort_and_discard_pending_req_states already dispatches the concrete pending rids directly before removing their tokenizer state. Please either retain the existing guard in abort_request, or make prefix/group cancellation explicit in the protocol and use exact matching for concrete request IDs. A regression test should cover both invariants: disconnect cleanup dispatches before the pop, while an unknown/stale public rid cannot cancel a live request merely because it is a prefix.
|
Second reproduction, this time on CUDA / H200, with a version boundary that may help narrow the regression. Setup: DeepSeek-V4-Flash-0731, TP=2 on 2×H200, Version boundary
Totals from an A/B/A/B benchmark (each version measured twice, three load levels per arm, ~3.5 h in total, identical flags, only the image digest changing):
The bursts are clustered into 2–3 minute windows (579 / 404 / 176, then 756 / 508, then 278 / 649) rather than spread as background noise — consistent with a handful of orphaned generations each emitting hundreds of lines while decoding to their limit, not with a logging-only issue. Two things that may matter for triage:
We have deferred our v0.5.18 upgrade because of this. Happy to re-run the same A/B benchmark against either this PR or #35255 on the same hardware if that would help you choose between them. |
|
Confirmed — reproduced against Fixed in 5eb93a990a:
Also corrected the PR body's regression chain while at it: #32588 didn't create the dispatch blocker on its own — it made the cleanup abort dispatched requests before dropping them (and was cherry-picked into v0.5.17 as @bitfinop this branch keeps the zombie fix your benchmark targets — a re-run against |
… disconnect A streaming client disconnect raises CancelledError/GeneratorExit inside generate_request; the handler cleanup popped rid_to_state entries without telling the scheduler, and the delayed create_abort_task that fires 2s later is dropped by the rid_to_state guard in abort_request(), so the scheduler kept decoding the request until its generation limit while TokenizerManager logged 'state was deleted' for every streamed chunk. Replace the pop-only _discard_pending_req_states with _abort_and_discard_pending_req_states, which dispatches AbortReq for each concrete, still-tracked rid BEFORE popping its state. The public abort_request() guard is left untouched, so unknown/stale rids are still dropped at the tokenizer (scheduler abort matching is prefix-based) and the delayed task becomes a no-op after cleanup -- exactly one AbortReq per disconnected request. Repair the registered rid-cleanup unit tests for the renamed helper and add tokenizer_ipc_name to the mocked manager (cleanup now dispatches to the scheduler), and add a 13-case regression suite covering both lifecycle invariants: disconnect cleanup dispatches before the pop (including per-rid batch ordering and delayed-task no-op), and unknown/stale/prefix/duplicate public rids are never dispatched.
5eb93a9 to
7b8496b
Compare
|
Rebased onto latest |
If dispatching an AbortReq fails in _abort_and_discard_pending_req_states (e.g. a broken scheduler socket during shutdown), the exception used to abort the cleanup loop mid-way: remaining rid_to_state entries leaked and the original CancelledError/GeneratorExit was masked by the dispatch error. Wrap the dispatch in try/except Exception with the pop in a finally block -- the failure is logged, the state is still removed, and the loop continues with the remaining rids, matching the guarded dispatch in earlier implementations of this cleanup. Add regression coverage: a batch cleanup where the middle dispatch raises still pops every rid and keeps aborting the rest, and a generate_request-level test asserts the original CancelledError survives a dispatch failure during cleanup.
|
Added one failure-path hardening change ( |
|
Production confirmation on 8×H20 (CUDA, SM90) with v0.5.18 + DeepSeek-V4-Flash-0731 + DSPARK Adding another production data point matching this exact issue, on NVIDIA H20 with sglang v0.5.18, DeepSeek-V4-Flash-0731 (FP4 routed experts / marlin runner), DSPARK ( Scale observed (2026-08-25, 24h window):
Impact confirmed in production: orphans occupy running slots under Happy to provide full log excerpts or run verification builds if helpful. This fix matters a lot for production agent workloads — hoping to see it land for 0.5.19. |
…nt disconnect (sgl-project#35936) On client disconnect, CancelledError/GeneratorExit (both BaseException) reaches the generate_request cleanup, which popped rid_to_state entries immediately. The delayed create_abort_task then hit the rid_to_state guard in abort_request and silently skipped the dispatch, so the scheduler never learned the client was gone and kept decoding to max_tokens, flooding logs with 'state was deleted in TokenizerManager' and burning GPU slots. Replace the pop-only cleanup with _abort_and_discard_pending_req_states: dispatch AbortReq for each still-pending rid BEFORE removing its state, and keep the public abort_request rid_to_state guard so unknown/stale rids cannot trigger broad prefix-based cancellation (scheduler abort matching is startswith-based). A dispatch failure during cleanup is logged and cleanup continues (finally) so a broken scheduler socket cannot leak entries.
|
Confirmation from a different code lineage and GPU class: applied this PR's The diff applies file-level unchanged to that base (only the method rename in Before: one cancelled streaming request left the scheduler decoding it to its configured max_tokens. Observed 61,976 "Received output for rid=... but the state was deleted" lines over ~2 minutes with After: streamed ~8 s (~1,600 chunks), disconnected mid-generation → zero "state was deleted" lines and zero further decode batches; the slot freed immediately and the next request served normally. |
|
#35255 covers this and was merged on Sep 4. It keeps the state until the scheduler replies instead of deleting it immediately, so no Numbers from the v0.5.19 release build (DeepSeek-V4-Flash, TP=2, DSpark, |
|
Update from our side (we reported the 8×H20 production numbers upthread, 31,063 lines / 28 rids per 24h on v0.5.18): we are now 13 days into running v0.5.19 + this PR as a single-file Result on v0.5.19 + this patch: On @bitfinop's note that #35255 was merged to main on Sep 4 — thanks, that's the cleaner long-term path since it also restores the abort lost during chunked prefill, which this PR doesn't cover (we run If this PR is now considered superseded by #35255 and won't be merged, a short note to that effect would also help — the production validation data in this thread (H200 / MI300X / RTX 6000 / H20) would then live under the winning PR's references. Either way, thanks @Cayrop — this fix has been carrying our production since Aug 25. |
Problem
Streaming clients that disconnect mid-generation (Esc in an agent UI, network drop, proxy timeout) leave orphaned requests decoding on the scheduler until the request reaches its configured generation limit, while TokenizerManager spams thousands of:
Observed on an AMD MI300X deployment (ROCm) and reproduced on main @
5a46d65(2026-08-21); independently reported by @bitfinop below on CUDA/H200 with a clean v0.5.17 ↔ v0.5.18 boundary. A single interrupted 4k-token request produced more than 5,000 error messages over several minutes and kept consuming GPU decode throughput as a zombie.Version note (verified from git history): the released v0.5.17 tag (
2948168546, 2026-08-07) already contains #32588's cleanup-time abort dispatch (cherry-pick283f505f9c, 2026-08-05), so only builds of that series predating 2026-08-05 exhibit this exact failure mode. The broken combination exists on main from #34160 (2026-08-09) onward — see chain below.Root cause
CancelledError/GeneratorExitis raised insideTokenizerManager.generate_request.except BaseException:and immediately deletesrid_to_state[rid]via the pop-only_discard_pending_req_states.create_abort_taskfiresabort_request(rid)- but its guard (rid not in self.rid_to_state -> return) silently drops the dispatch because the state was already deleted in step 2.AbortReqand keeps decoding; every streamed chunk then hits the missing-state error path.Regression chain:
abort_request(), so dispatch was never gated on state presence.except Exception:- deliberately not catchingCancelledError, so disconnects were unaffected.except BaseException:and compensated: the same helper aborted dispatched requests before dropping them, andabort_request()dropped unknown rids itself. It was cherry-picked into release/v0.5.17 (283f505f9c).except BaseException:but restored the pop-only helper and the old guard (71043b9dbb, 2026-08-09). This is where the broken combination first appeared - after the v0.5.17 tag (2026-08-07) and before v0.5.18 (71de97b264, 2026-08-20), matching the independent H200 A/B report.Fix
All changes are in
python/sglang/srt/managers/tokenizer_manager.py:generate_request()cleanup: replace the pop-only_discard_pending_req_stateswith_abort_and_discard_pending_req_states, which dispatchesAbortReqbefore popping each still-pending state, using concrete tracked rids only. Disconnect cleanup does not depend on the delayed background task; afterwards the delayedcreate_abort_taskhits therid_to_stateguard and is a no-op, so exactly oneAbortReqis sent per disconnected request.try/except Exceptionwith the pop in afinally- a broken scheduler socket is logged, cleanup continues for the remaining requests, tokenizer state is still removed, and the originalCancelledError/GeneratorExitis never masked.abort_request()is not touched: the public guard keeps exact-ID semantics. Scheduler abort matching is prefix-based (req.rid.startswith(recv_req.rid)at eight sites inscheduler.py, plus grammar/dLLM/PD-disaggregation paths), so forwarding unknown or stale public rids could cancel unrelated live work sharing a prefix - e.g.abort_request(rid="batch")matches livebatch_0..batch_10generated byGenerateReqInput._normalize_rid, and"batch_1"also matchesbatch_10. An earlier revision of this PR removed the guard; that was wrong (found in review) and was reverted./abort_requestwith an already-orphaned rid therefore remains a documented no-op.Rebased onto latest
main(d1af3c8923), where the guard is present upstream after the config-bags refactor (#35906); the remaining diff vs main is the cleanup fix, the failure-path hardening, and tests.Repro
Before: thousands of
state was deletedlines;#running-reqstays elevated for minutes.After: <=2 backlog lines, decode stops within ~1 s.
Verification
/abort_requestwith bogus/stale rid (e.g. prefix likebatch)/abort_requestwith orphaned ridUnit coverage (CPU-only, mock-based): new
test/registered/unit/managers/test_abort_lifecycle_regression.py(15 cases: unknown/stale/prefix/duplicate public rids never dispatched; disconnect cleanup dispatch-before-pop incl. per-rid batch ordering; delayed-task no-op; normal completion emits no abort; dispatch-failure tolerance incl.CancelledErrorpreservation;_normalize_ridscheme + scheduler predicate characterization) plus the repaired registeredtest_tokenizer_manager_rid_cleanup.py: 33 passed. The pre-review head broke 5 of those registered tests (renamed helper, missingtokenizer_ipc_namemock) — repaired here.GPU verification on SGLang commit 5a46d65 (main @ 2026-08-21, ROCm build), Qwen3.8-27B (BF16) on AMD MI300X (ROCm), TP=1, FP8 E4M3 KV cache.
CI States
Latest PR Test (Base): ❌ Run #32655915755
Latest PR Test (Extra): ❌ Run #32655915461
Latest PR Test (AMD ROCm 7.2): ❌ Run #32655915610