fix: correct Retry-After date header unit mismatch in retry backoff#308
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
fix: correct Retry-After date header unit mismatch in retry backoff#308MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
In `getRetryBackoffDuration`, when the `Retry-After` header contains an HTTP-date value, `ChronoUnit.MILLIS.between()` was used to compute the delay. This returns a value in milliseconds, but the result is then passed to `Duration.ofNanos()`, treating it as nanoseconds. This means the actual backoff would be ~1,000,000x shorter than the server requested (e.g., a 5-second Retry-After would become 5 microseconds instead of 5 seconds). The other two code paths (Retry-After-Ms and numeric Retry-After) correctly convert their values to nanoseconds before reaching the `Duration.ofNanos()` call. This fix changes `ChronoUnit.MILLIS` to `ChronoUnit.NANOS` so all three paths produce consistent nanosecond values.
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.
Summary
Retry-Afterheader contains an HTTP-date (e.g.,Wed, 21 Oct 2015 07:28:00 GMT), the retry backoff duration is ~1,000,000x shorter than the server requested.ChronoUnit.MILLIS.between()returns milliseconds, but the result flows intoDuration.ofNanos(), which interprets it as nanoseconds.ChronoUnit.MILLIStoChronoUnit.NANOSso the date-based path produces nanoseconds consistently with the other two code paths (Retry-After-Msand numericRetry-After).Before (bug)
A
Retry-After: Wed, 09 Oct 2024 07:28:05 GMTheader (5 seconds in the future) would compute:After (fix)
The other two branches already convert correctly to nanoseconds:
Retry-After-Ms:toFloat() * TimeUnit.MILLISECONDS.toNanos(1)→ nanosecondsRetry-After(numeric):toFloat() * TimeUnit.SECONDS.toNanos(1)→ nanosecondsTest plan
execute_withRetryAfterHeadertest still passes (it uses a no-op sleeper, so it validates the flow but not the duration value)Retry-Afterheader would fully validate this fixAI Disclosure
This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).