refactor!: share one exponential backoff calculation - #1646
Open
spydon wants to merge 2 commits into
Open
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Tr00d
approved these changes
Aug 5, 2026
Three copies of the same doubling-with-a-cap math lived in the repo: `RetryOptions.delay` in supabase_common, realtime's `RetryTimer.createRetryFunction` and postgrest's default retry delay. They now all call `exponentialBackoff` in supabase_common, which takes a zero based attempt, doubles from `initialDelay` and caps at `maxDelay`, with optional jitter. The three call sites keep their existing delays: realtime still counts `tries` from one and returns milliseconds, `RetryOptions` still treats attempt zero as no delay, and postgrest still starts at one second and caps at thirty. `maxShift` in realtime_client is gone; the exponent clamp that kept the doubling from overflowing now lives with the shared calculation. Part of #1572 (tier 3), under the v3 umbrella #1278.
spydon
force-pushed
the
breaking/shared-http-method
branch
from
August 5, 2026 15:14
9a136d8 to
4b05226
Compare
spydon
force-pushed
the
breaking/shared-exponential-backoff
branch
from
August 5, 2026 15:15
c2b1b6c to
549c593
Compare
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.
Tier 3 of #1572, third of four PRs. Stacked on #1645 (which is stacked on #1644).
What
The same "double the delay, cap it" math existed in three places:
RetryOptions.delay(supabase_common)delayFactor * pow(2, min(attempt, 31)) * jitter, capped atmaxDelayRetryTimer.createRetryFunction(realtime_client)firstDelay << min(tries - 1, maxShift), capped atmaxDelay, in millisecondsPostgrestBuilder._defaultRetryDelayDuration(seconds: min(pow(2, attempt), 30))All three now call one helper in
supabase_common:attemptis zero based, so attempt0waitsinitialDelayand each attempt after that doubles untilmaxDelay. Jitter is opt-in per caller, since only the storage upload retry uses it today.No behaviour change
Each call site keeps the delays it had:
triesand its millisecond return type, soRealtimeClient(reconnectAfterMs: ...)and theTimerCalculationtypedef are untouched. It just passestries - 1to the helper.RetryOptions.delaykeeps returningDuration.zerofor attempt0and keeps its jitter.maxShift(a public top-level const inrealtime_client) is removed: the exponent clamp that stops the doubling from overflowing now lives with the shared calculation. It was not registered in the compliance matrix.Realtime's millisecond-based options (
reconnectAfterMs,heartbeatIntervalMs,longpollerTimeout) would read better asDurations, but converting them is a separate change; doing onlyreconnectAfterMshere would leave that API half converted.Testing
New
backoff_test.dartcovers the start delay, the doubling, the cap, the absence of jitter by default and the jitter bounds with an injectedRandom.realtime_client's existingretry_timer_test.dartand postgrest'sretry_test.dartpass unchanged, which is the real check that the delays did not move.melos analyzeandmelos formatclean;gotrue,postgrest,storage_client,realtime_client,supabaseandsupabase_commonsuites pass against the local stack. Capability matrix symbol and drift checks pass.