Skip to content

Commit a8b6409

Browse files
authored
Merge pull request #4 from wiz-sec/dont-retry-if-need-to-wait-longer-than-max-time
Don't wait if needed to wait more than max time
2 parents aa69c27 + 95c4cad commit a8b6409

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,7 @@ func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response)
552552
if resp != nil {
553553
if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
554554
if sleep, ok := parseRetryAfterHeader(resp.Header["Retry-After"]); ok {
555-
if sleep <= max {
556-
return sleep
557-
}
555+
return sleep
558556
}
559557
}
560558
}
@@ -754,6 +752,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
754752
}
755753

756754
wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp)
755+
if wait > c.RetryWaitMax { // If the server wants us to wait longer than we are allowed, give up.
756+
break
757+
}
757758
if logger != nil {
758759
desc := fmt.Sprintf("%s %s", req.Method, redactURL(req.URL))
759760
if resp != nil {

0 commit comments

Comments
 (0)