From 9f2c5ca59f4c99e70a97d820f1acae34b856b364 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Sun, 18 Jul 2021 16:47:34 +0800 Subject: [PATCH] pkg: fix retry getBackoffInMs panic when sleep overflowed (#2280) (#2287) --- pkg/retry/retry_with_opt.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/retry/retry_with_opt.go b/pkg/retry/retry_with_opt.go index b4af380b582..7bf666777b1 100644 --- a/pkg/retry/retry_with_opt.go +++ b/pkg/retry/retry_with_opt.go @@ -88,7 +88,10 @@ func getBackoffInMs(backoffBaseInMs, backoffCapInMs, try float64) time.Duration if temp <= 0 { temp = 1 } - sleep := temp + rand.Int63n(temp) - backOff := math.Min(backoffCapInMs, float64(rand.Int63n(sleep*3))+backoffBaseInMs) + sleep := (temp + rand.Int63n(temp)) * 3 + if sleep <= 0 { + sleep = math.MaxInt64 + } + backOff := math.Min(backoffCapInMs, float64(rand.Int63n(sleep))+backoffBaseInMs) return time.Duration(backOff) * time.Millisecond }