Repository navigation
fix(storage): keep a minimum wait between resumable upload retries - #1866
Conversation
The draft auto_retry specs (supabase/sdk PR 190) draw the wait before the n-th retry from 0...min(maxDelay, baseDelay * 2^(n-1)). RetryPolicy drew it from cap/2...cap (equal jitter). Full jitter spreads clients that failed together over the whole window, and matches the Realtime reconnect backoff. backoffDelay(retry:random:) takes the jitter source so tests can pin it.
… and Realtime RetryPolicy.backoffDelay repeated the full-jitter math of Realtime's BackoffPolicy. Move BackoffPolicy into Helpers, which Realtime already depends on, and have RetryPolicy delegate to it. Move its tests to HelpersTests and drop the randomized RetryPolicy backoff test that the pinned-jitter test now covers.
- The interceptor test now runs ten retries and checks that the wait window grows, so a wrong retry number fails it. - The default random test draws 200 delays and checks they spread over the window. - RetryPolicyTests keeps one delegation check instead of repeating BackoffPolicy's tests. - The RetryPolicy doc no longer says it drives Realtime's reconnect delays.
The resumable upload loop has a time budget (retryTimeout) but no attempt limit. With full jitter (0...cap) in the shared backoff, waits can be near zero, so the loop could send a burst of retries to a failing server. Each retry now waits a random duration in cap/2...cap, so the waits grow as the docs say and the budget bounds the attempt count.
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix Merge Risk:
|
Coverage Report for CI Build 44367387824Coverage increased (+0.001%) to 96.194%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Stacked on #1860.
#1860 changes the shared HTTP backoff to full jitter (
0...cap). The resumable upload loop inSources/Storage/ResumableUpload.swifthas no attempt limit. OnlyretryTimeoutstops it, and it counts only the sleep time. With full jitter, waits can be near zero, so the loop can send many quick retries to a server that already fails. The docs also say the waits grow.Fix
The loop now waits a random duration in
cap/2...cap(equal jitter), withcapfromRetryPolicy.default. This keeps the old minimum wait for this loop only. The time budget then bounds the attempt count again. The auto_retry spec draft (supabase/sdk#190) covers per-request retries with an attempt limit. It does not cover the resumable loop, so this keeps the loop's time-budget model.Sources/Helpersdoes not change.Test
everyRetryWaitsAtLeastHalfTheBackoffCaprecords each sleep through a clock and checks that every wait is incap/2...cap. It failed before the fix (2 waits under the floor) and passes after it.ResumableUploadTests: 27 tests pass.