From 031c71932b5a0bb0715cf81169c8a5f8b334074c Mon Sep 17 00:00:00 2001 From: Abdullah Amjad Date: Mon, 1 Aug 2022 16:39:13 +0200 Subject: [PATCH] updated DefaultBackoff to return min of Retry-After header or RetryWaitMax --- client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index f40d241..d89434f 100644 --- a/client.go +++ b/client.go @@ -512,7 +512,11 @@ func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable { if s, ok := resp.Header["Retry-After"]; ok { if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil { - return time.Second * time.Duration(sleep) + sleepDuration := time.Second * time.Duration(sleep) + if sleepDuration < max { + return sleepDuration + } + return max } } }