fix(api): let only one request probe a half-open circuit - #414
Open
Ivancheng7 wants to merge 1 commit into
Open
Ivancheng7 wants to merge 1 commit into
Ivancheng7 wants to merge 1 commit into
Conversation
isAvailable() returned true for every request while the circuit was half-open, so a traffic burst was admitted in full to a bot that had not actually recovered — and the burst finished halfOpenMaxAttempts quickly, closing the circuit without a verified recovery. - Track halfOpenProbeInFlight: the request that transitions open -> half-open takes the probe slot; further requests are rejected until it settles. - recordSuccess()/recordFailure() release the slot; a failed probe re-opens the circuit as before. - New tests/circuit-breaker.test.ts: one probe per window with a burst behind it, successful probe sequence closes, failed probe re-opens and the next window gates again.
This branch has not been deployed
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
Once a circuit turns
half-open,isAvailable()returnstruefor every request — the "probe" is not a probe. Under load all requests that arrive while the probe is in flight are admitted to a bot that has not recovered yet, and the burst also driveshalfOpenSuccessestohalfOpenMaxAttempts, closing the circuit without any genuine recovery having been verified.Fix
Track
halfOpenProbeInFlighton the circuit:open → half-opentakes the probe slot;recordSuccess()/recordFailure(), and a failed probe re-opens the circuit exactly as before.Tests
New
tests/circuit-breaker.test.ts:Full local suite: no new failures.