Skip to content

Commit 3cec72f

Browse files
authored
Merge pull request #72 from infosiftr/retry-500
Treat "500 Internal Server Error" and "502 Bad Gateway" the same as a 503
2 parents 2435fce + 08727fe commit 3cec72f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

registry/rate-limits.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func (d *rateLimitedRetryingRoundTripper) RoundTrip(req *http.Request) (*http.Re
2424
// cap request retries at once per second
2525
requestRetryLimiter = rate.NewLimiter(rate.Every(time.Second), 1)
2626

27-
// if we see 3x 503 during retry, we should bail
28-
maxTry503 = 3
27+
// if we see 3x (503 or 502 or 500) during retry, we should bail
28+
maxTry50X = 3
2929

3030
ctx = req.Context()
3131
)
@@ -53,9 +53,9 @@ func (d *rateLimitedRetryingRoundTripper) RoundTrip(req *http.Request) (*http.Re
5353
doRetry = true // TODO maximum number of retries? (perhaps a deadline instead? req.WithContext to inject a deadline? 👀)
5454
}
5555

56-
// 503 should result in a few auto-retries (especially with the automatic retry delay this injects), but up to a limit so we don't contribute to the "thundering herd" too much in a serious outage
57-
if res.StatusCode == 503 && maxTry503 > 1 {
58-
maxTry503--
56+
// certain status codes should result in a few auto-retries (especially with the automatic retry delay this injects), but up to a limit so we don't contribute to the "thundering herd" too much in a serious outage
57+
if (res.StatusCode == 503 || res.StatusCode == 502 || res.StatusCode == 500) && maxTry50X > 1 {
58+
maxTry50X--
5959
doRetry = true
6060
// no need to eat up the rate limiter tokens as we do for 429 because this is not a rate limiting error (and we have the "requestRetryLimiter" that separately limits our retries of *this* request)
6161
}
@@ -81,7 +81,7 @@ func (d *rateLimitedRetryingRoundTripper) RoundTrip(req *http.Request) (*http.Re
8181
}
8282

8383
// TODO some way to notify upwards that we retried?
84-
// TODO implement more backoff logic than just one retry per second + docker hub rate limit (+ limited 503 retry)?
84+
// TODO implement more backoff logic than just one retry per second + docker hub rate limit (+ limited 50X retry)?
8585
continue
8686
}
8787

0 commit comments

Comments
 (0)