Guard against overflow in retry

This commit is contained in:
Vladimir Mihailenco 2020-10-28 11:12:46 +02:00
parent 38caa12762
commit f92951b835
1 changed files with 4 additions and 0 deletions

View File

@ -15,6 +15,10 @@ func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration
} }
d := minBackoff << uint(retry) d := minBackoff << uint(retry)
if d < minBackoff {
return maxBackoff
}
d = minBackoff + time.Duration(rand.Int63n(int64(d))) d = minBackoff + time.Duration(rand.Int63n(int64(d)))
if d > maxBackoff || d < minBackoff { if d > maxBackoff || d < minBackoff {