1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-12 14:21:52 +03:00

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

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 {