fix: clamp negative Retry-After delays - #878
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
Conversation
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
Treat negative or already-elapsed
Retry-Afterdelays as zero before passing them to the retry sleeper.Fixes #853.
Problem
RetryingHttpClientparses three server-directed retry-delay forms:Retry-After-Msnumeric milliseconds;Retry-Afternumeric seconds;Retry-AfterHTTP dates.The parsed value is currently converted directly to
Durationand passed toSleeper.That means values such as:
can produce a negative duration. With the default sleeper, that can make a retryable response fail while trying to sleep instead of retrying immediately.
Past HTTP dates are especially normal under clock skew or network transit: once the requested instant has passed, the remaining delay is simply zero.
Fix
Clamp the parsed nanosecond delay at the shared retry-delay boundary:
This is applied after all supported
Retry-Afterparsing, so both synchronous and asynchronous retry paths receive the same non-negative duration.Invalid/unparseable headers continue to fall back to the existing exponential backoff behavior.
Regression coverage
Added focused sync/async coverage for:
Retry-Afterseconds;Retry-After-Msmilliseconds;All three cases require exactly
Duration.ZEROand a successful retry.Validation
mainat6a46d024ed67e2be889a4c729837a664d5e7902c;RetryingHttpClient.kt;Full repository validation is left to GitHub Actions because this environment does not have a complete local checkout/toolchain for the repository.
Risk
Low. Positive server-directed delays are unchanged. Only negative parsed delays are normalized to zero, which is equivalent to the requested retry time already having elapsed.