From d67f3fe6995bb51fda6b0ec85aa666cb0b1c198c Mon Sep 17 00:00:00 2001 From: acetaxxxx Date: Mon, 10 Feb 2025 11:43:34 +0800 Subject: [PATCH] Prevent client infinite retry The retry function won't stop when it reaches max retires limit. Signed-off-by: acetaxxxx --- retry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/retry.go b/retry.go index 1d5ce86..54059f0 100644 --- a/retry.go +++ b/retry.go @@ -21,6 +21,9 @@ type RetryDelayFn func(attempts int, cmd Completed, err error) time.Duration // max delay is 1 second. // This "Equal Jitter" delay produced by this implementation is not monotonic increasing. ref: https://aws.amazon.com/ko/blogs/architecture/exponential-backoff-and-jitter/ func defaultRetryDelayFn(attempts int, _ Completed, _ error) time.Duration { + if attempts >= defaultMaxRetries{ + return -1 + } base := 1 << min(defaultMaxRetries, attempts) jitter := util.FastRand(base) return min(defaultMaxRetryDelay, time.Duration(base+jitter)*time.Microsecond)