fix(retry): honor the retryAfter option in the default retry strategy - #5683
Open
codeAnqiang-ma wants to merge 1 commit into
Open
fix(retry): honor the retryAfter option in the default retry strategy#5683codeAnqiang-ma wants to merge 1 commit into
codeAnqiang-ma wants to merge 1 commit into
Conversation
The retryAfter option is documented as a boolean that controls whether the delay before the next retry is inferred from the Retry-After response header. It was stored in the handler options but never read: the default retry strategy always used the Retry-After header, so setting retryAfter: false had no effect and the server kept controlling the retry delay instead of the configured exponential backoff. Signed-off-by: codeAnqiang-ma <273298913+codeAnqiang-ma@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
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.
This relates to...
Fixes #5682
Rationale
retryOptions.retryAfteris documented (RetryHandler.md, RetryAgent.md, and the JSDoc intypes/retry-handler.d.ts) as a boolean that controls whether the delay before the next retry is inferred from theRetry-Afterresponse header, with a default oftrue. The option was normalized and stored in the constructor but never read: the default retry strategy always used the header, soretryAfter: falsesilently had no effect and the server kept controlling the retry delay (up tomaxTimeout) instead of the configured exponential backoff.Changes
lib/handler/retry-handler.js: the default retry strategy now destructuresretryAfterfromretryOptionsand skips theRetry-Afterheader when the option is explicitlyfalse. Behavior for the default (true) and for any other value is unchanged.test/retry-handler.js: regression test (fails before the fix, passes after) modeled on the neighboring "Should retry immediately when retry-after is zero" test: a 429 withretry-after: 60andretryAfter: falsemust schedule the retry via the exponential backoff (500ms), not the header (60s).Features
N/A
Bug Fixes
retryOptions.retryAfter: falsenow disablesRetry-After-based delay inference as documented, affectingRetryHandler,RetryAgent, andinterceptors.retry().Breaking Changes and Deprecations
N/A — only the documented-but-inert
retryAfter: falsepath changes behavior.Status
Test evidence (Node v22.22.3, macOS):
npm run lintpasses. Not run: the full test suite (only retry-related files, listed above).Repro from #5682 before/after the fix: fails after ~10s on
main(delay taken fromRetry-After: 10), fails after ~360ms with this patch (exponential backoff withminTimeout: 100), as expected forretryAfter: false.Disclosure: this fix was prepared with AI assistance; I reproduced the bug locally and reviewed every change. Signed off per the DCO.