Skip to content

Commit

Permalink
Better rate-limit support
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Vrba <jiri.vrba@firma.seznam.cz>
  • Loading branch information
Jiri Vrba committed Feb 16, 2024
1 parent a4e7315 commit 76fbe83
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/pkg/reg/adapter/dockerhub/adapter.go
Expand Up @@ -128,11 +128,10 @@ func getAdapterInfo() *model.AdapterPattern {

// Rate-limit aware wrapper function for client.Do()
// - Avoids being hit by limit by pausing requests when less than 8 requests remaining.
// - Pauses when limit is hit.
// - Pauses for given time when limit is hit.
// - Allows 2 more attempts before giving up.
// Reason: Observed (02/2024) penalty for hitting the limit is 120s, normal reset is max. 60s,
//
// so it is better to not hit the wall.
// Reason: Observed (02/2024) penalty for hitting the limit is 120s, normal reset is 60s,
// so it is better to not hit the wall.
func (a *adapter) limit_aware_http_do(method string, path string, body io.Reader) (*http.Response, error) {
var attempts_left int = 3
for attempts_left > 0 {
Expand All @@ -153,7 +152,6 @@ func (a *adapter) limit_aware_http_do(method string, path string, body io.Reader
if err != nil {
return resp, err
}

if remaining_req < 8 {
reset_at, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-reset"), 10, 64)
if err != nil {
Expand Down

0 comments on commit 76fbe83

Please sign in to comment.