fix: retry middleware corrupts exponential backoff state#690
Open
Abzaek wants to merge 1 commit into
Open
Conversation
… in operation function The Retry middleware's operation function called expBackoff.NextBackOff() inside ShouldRetry and OnRetryHook callbacks, which advanced the exponential backoff's internal state machine. When backoff.Retry then called NextBackOff() to determine the actual sleep duration, it received a future interval, effectively skipping one or more intermediate delays. For example, with InitialInterval=10ms, Multiplier=2.0, the sequence of actual sleep durations was: 20ms, 40ms, 80ms, 160ms instead of the correct: 10ms, 20ms, 40ms, 80ms. The fix computes the approximate delay from the retry configuration without mutating any backoff state, preserving the correct exponential backoff sequence used by the backoff.Retry framework. Signed-off-by: Abdulazez A. <[email protected]>
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.
Bug
The Retry middleware in
message/router/middleware/retry.gocorrupts the exponential backoff state machine by callingexpBackoff.NextBackOff()inside theoperationfunction.Root Cause
The
operationfunction passed tobackoff.Retry()was callingexpBackoff.NextBackOff()for two purposes:ShouldRetrycallbackOnRetryHookcallbackEach call to
NextBackOff()advances the backoff's internal state. Whenbackoff.Retry()itself then callsNextBackOff()to determine the actual sleep duration, it receives a future interval.Impact
Retry delays were double what they should be. With
InitialInterval=10ms,Multiplier=2.0:Fix
Replaced
NextBackOff()calls with a new pure functioncomputeBackoffDelay_atRetryNum()that computes the approximate delay from the config parameters without mutating any state. This letsbackoff.Retry()continue to drive actual sleep durations correctly.Test Results
All existing tests pass (
go test ./...— all green).Fixes #224 (partial)