Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Don't fall back to http on 5xx response (#344)
Browse files Browse the repository at this point in the history
* Don't fall back to http on 5xx response

When retching the registry limit we will get 503 or if the registry is having some problems we will get 5xx in response. In this case we don't want to fallback to http because it can make the build fail and retry the same request instead.

* move httpFallbackDisabled into a variable
  • Loading branch information
ahmagdy authored Aug 26, 2020
1 parent abbdf51 commit e9b23cd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/utils/httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,15 @@ func Send(method, rawurl string, options ...SendOption) (resp *http.Response, er
opts.retry.backoffMax)
}
resp, err = client.Do(req)

httpFallbackDisabled := opts.httpFallbackDisabled
if !httpFallbackDisabled && is5xxResponse(resp) {
httpFallbackDisabled = true
}
// Retry without tls. During migration there would be a time when the
// component receiving the tls request does not serve https response.
// TODO (@evelynl): disable retry after tls migration.
if err != nil && req.URL.Scheme == "https" && !opts.httpFallbackDisabled {
if err != nil && req.URL.Scheme == "https" && !httpFallbackDisabled {
log.Warnf("Failed to send https request: %s. Retrying with http...", err)
var httpReq *http.Request
httpReq, err = newRequest(method, opts)
Expand Down Expand Up @@ -385,3 +390,7 @@ func min(a, b time.Duration) time.Duration {
}
return b
}

func is5xxResponse(resp *http.Response) bool {
return resp != nil && resp.StatusCode >= 500
}

0 comments on commit e9b23cd

Please sign in to comment.