mixclient: Avoid jitter calculation panic #3448
Merged
+2
−2
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.
rand.Duration
may not be called with a negative or zero upper bound, but this was seen to occur in(*Client).prDelay()
. Two notable possible bugs stood out.First, if
sendBefore
is exactly equal tonow
, then it will not be incremented by another epoch duration, leading to a potential invalidrand.Duration
parameter. This is corrected by also checking for the times equaling exactly.Second,
time.Until()
causes an additional call totime.Now()
, which we have already fetched and all calculations must be based on it. IfsendBefore.Sub(now)
is an extremely small value, it is possible thattime.Until(sendBefore)
now returns a small negative or zero duration. This is corrected by replacing thetime.Until
call withsendBefore.Sub(now)
.