Skip to content

fix: randomize retry backoff jitter - #30

Merged
velocitysystems merged 1 commit into
silvermine:masterfrom
gabref:fix/retry-backoff-jitter
Nov 13, 2026
Merged

velocitysystems merged 1 commit into
silvermine:masterfrom
gabref:fix/retry-backoff-jitter

Conversation

@gabref

@gabref gabref commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Retry jitter currently uses clock nanoseconds modulo a millisecond count. Coarse clocks can make the first retry's jitter always zero, so clients wait the same 100ms and retry together. Use a fresh RandomState for each calculation so the default first retry can span 100–199ms independently of clock resolution, without adding a dependency.

Extract the exponential backoff calculation into a pure function accepting a random value. Add deterministic coverage for every millisecond offset in the default first three retry windows and the capped 5–10s window, inputs that are multiples of 100 and 1000, modulo wrapping, and duration/overflow edge cases. Update the production jitter test to exercise default retries 1–3 without sleeps or the prime-window workaround.

Preserve the backoff formula, retry defaults, and Retry-After behavior, including existing millisecond rounding that yields zero delay when the capped base is below 2ms.

Closes #25

Use a fresh RandomState instead of clock nanoseconds so coarse clocks
do not synchronize retries. Keep equal jitter and Retry-After behavior.

Extract the pure backoff calculation and cover default retry windows,
coarse inputs, long delays, and existing rounding behavior.

Closes silvermine#25
@gabref
gabref requested a review from a team November 13, 2026 09:41
@velocitysystems
velocitysystems merged commit 71dd16e into silvermine:master Nov 13, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use a real random source for retry backoff jitter

2 participants