feat(async/unstable): add getDelay option to retry() - #7317
Open
tomas-zijdemans wants to merge 1 commit into
Open
feat(async/unstable): add getDelay option to retry()#7317tomas-zijdemans wants to merge 1 commit into
tomas-zijdemans wants to merge 1 commit into
Conversation
Adds an unstable retry() entrypoint whose getDelay hook selects the wait before each retry, so a caller can honor Retry-After without owning the retry loop. The hook receives the thrown value, the 1-based failed attempt number, and the delay the backoff computed; its return value replaces the whole wait, without further jitter or clamping.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7317 +/- ##
=======================================
Coverage 95.03% 95.04%
=======================================
Files 617 618 +1
Lines 51637 51723 +86
Branches 9359 9388 +29
=======================================
+ Hits 49075 49160 +85
Misses 2021 2021
- Partials 541 542 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Adds
getDelayto an unstableretry(), so the caller picks the wait before each retry.Right now a 429 with
Retry-After: 30cannot be honored.retry()computes the backoff inside the loop and never lets it out, so a caller who knows how long the server wants to be left alone has three bad options: sleep insidefnand get std's backoff added on top, rewrite the loop to change one number, or stop retrying and hand the problem upstairs. Two clients I work with took the first two.The hook runs after
isRetriableaccepts the error and the attempt budget is checked, right before the wait:Header parsing stays with the caller.
@std/asyncgains no HTTP dependency.Worth arguing about
minTimeout/maxTimeoutclamp. Clamping could retry before the server asked, which is the bug this exists to fix.TypeErrorfor a non-number,RangeErrorfor a negative number orNaN, no quiet fallback to the computed delay.Infinityis legal and waits until the signal aborts. It does not mean "stop retrying".RetryOptionsand re-exportsRetryError, soinstanceofholds across both entrypoints. Stableretry()is untouched.Testing
21 tests on the new entrypoint, with
FakeTimeand a stubbedMath.random: hook ordering, overrides above the cap and below the base, invalid returns, aborts before, during and inside the hook, zero, fractions, waits past2 ** 31 - 1, and cancellableInfinity. The new module is at 100% line, branch and function coverage.deno task okanddeno task typosare clean apart from fourfs/walk_test.tsfailures that reproduce onmainin my environment.Follows #7296. #7297 proposed an observation-only
onRetryand is closed. ReturningcomputedDelayafter logging covers that case too.I used Claude Code to help investigate and write this change.