Don't lie about retrying in when jitter is enabled #18
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.
The
roko.Retrier
'sString()
method returns a message about the state of the retry loop, generally something of the formAttempt 3/19 Retrying in 6s
. Previously, when jitter was enabled for a retrier, the call toNextInterval()
within theString()
method and the actual retry loop itself would be totally independent, and so if random jitter was enabled, they'd return different results - ie,String()
would sayAttempt 3/19 Retrying in 5.42038947s
, but the retry loop would calculate a totally different value for jitter, and wait a longer or shorter amount of time.This wasn't so bad when jitter was limited to one second -
String()
might saynest attempt in 5.01s
, and then the retrier would actually sleep for5.99s
, but what's a second or two between friends, right?Unfortunately, in #17, some jabroni (me) added the ability for users to customise the range that jitter falls within, so it's now possible for
String()
to lie fairly significantly about the amount of time it's going to wait till the next request. If we configured a jitter range of [-10s, 30s] for our jitter range, the next interval reported byString()
could be off by as much as 40 seconds, which is pretty bad.This PR fixes this issue by refactoring
roko.Retrier
a little bit - now, at the start of the retry loop - before the callback is called - and stored in the state of the retrier. This means that any accesses to the next interval time will be consistent, even with jitter enabled.