Merge pull request #1549 from go-redis/feature/retry-overflow

Guard against overflow in retry
This commit is contained in:
Vladimir Mihailenco 2020-10-28 12:01:51 +02:00 committed by GitHub
commit 51a4ea4358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
if d < minBackoff {
return maxBackoff
}
d = minBackoff + time.Duration(rand.Int63n(int64(d)))
if d > maxBackoff || d < minBackoff {