Repository navigation
fix: randomize retry backoff jitter - #30
Merged
velocitysystems merged 1 commit intoNov 13, 2026
Merged
Conversation
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
velocitysystems
approved these changes
Nov 13, 2026
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.
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
RandomStatefor 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-Afterbehavior, including existing millisecond rounding that yields zero delay when the capped base is below 2ms.Closes #25