Repository navigation
fix(router): release the half-open circuit token on a panic from attempt - #8
Merged
Merged
Conversation
Serve calls b.CB.Allow() then p.attempt() then b.CB.Record(...) with no defer between them. httputil.ReverseProxy raises http.ErrAbortHandler as a real panic when a client disconnects mid-stream, which unwinds past Record and leaks the HalfOpenMax token forever, permanently denying every future probe on that backend. A mass client-abort event (e.g. a load driver hitting its timeout) can hit every router-fronted backend at once. runAttempt wraps the Allow-paired call so Record always runs, whether attempt returns or panics, and re-panics afterward so recoverMiddleware's existing ErrAbortHandler handling (metrics, logging) is unchanged. A client abort is classified Ignored, like a 429; any other panic is classified Failure. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Serve calls b.CB.Allow() then p.attempt() then b.CB.Record(...) with no defer between them. httputil.ReverseProxy raises http.ErrAbortHandler as a real panic when a client disconnects mid-stream, which unwinds past Record and leaks the HalfOpenMax token forever, permanently denying every future probe on that backend. A mass client-abort event (e.g. a load driver hitting its timeout) can hit every router-fronted backend at once. runAttempt wraps the Allow-paired call so Record always runs, whether attempt returns or panics, and re-panics afterward so recoverMiddleware's existing ErrAbortHandler handling (metrics, logging) is unchanged. A client abort is classified Ignored, like a 429; any other panic is classified Failure. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ekai into fix/circuit-breaker-halfopen-leak
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 statement
Running with the wekai router returned 502 upstream_unavailable for every single request — including a trivial hand-crafted curl — instantly (sub-3ms, meaning no real network call to the backend was ever attempted), while the vLLM workers behind them were confirmed completely healthy and idle (vllm:num_requests_running=0, direct curl succeeded). Restarting the router pod (which resets all in-memory state) immediately fixed it. This will recur under the same trigger condition.
Root cause
Fix
runAttempt wraps the Allow-paired call so Record always runs, whether attempt returns or panics, and re-panics afterward so recoverMiddleware's existing ErrAbortHandler handling (metrics, logging) is unchanged. A client abort is classified Ignored, like a 429; any other panic is classified Failure.
Tests done
Note
Medium Risk
Touches proxy serve-path panic handling and circuit breaker classification on client aborts; behavior change is narrowly scoped but affects recovery from mass client disconnects under load.
Overview
Fixes a permanent half-open circuit breaker deadlock when
httputil.ReverseProxypanics withhttp.ErrAbortHandlerafter a client disconnects mid-stream, which could skip the pairedRecordand leave the singleHalfOpenMaxprobe token leaked so backends never recover (instant502 upstream_unavailableuntil restart).Proxy.Servenow routes each admitted attempt throughrunAttempt, which always callscb.Recordon the normal path or inside arecoverbefore re-panicking. Client abort panics are recorded ascircuit.Ignored(like a 429); other panics asFailure, so outer middleware behavior stays the same while breaker bookkeeping stays exception-safe.Adds
proxy_test.goregression tests for abort vs other panics and for the unchanged successful probe path.Reviewed by Cursor Bugbot for commit 3b872b3. Bugbot is set up for automated code reviews on this repo. Configure here.