client-go: add connection refused to list of transient errors

Kubernetes-commit: 9aa68a5cf4b4195e5dfa9749380bc8d29be03522
This commit is contained in:
Michal Fojtik 2019-11-20 17:30:05 +01:00 committed by Kubernetes Publisher
parent c4788cee6e
commit 7c85ddb6ae

View File

@ -806,19 +806,24 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
r.backoff.UpdateBackoff(r.URL(), err, resp.StatusCode) r.backoff.UpdateBackoff(r.URL(), err, resp.StatusCode)
} }
if err != nil { if err != nil {
// "Connection reset by peer" is usually a transient error. // "Connection reset by peer", "Connection refused" or "apiserver is shutting down" are usually a transient errors.
// Thus in case of "GET" operations, we simply retry it. // Thus in case of "GET" operations, we simply retry it.
// We are not automatically retrying "write" operations, as // We are not automatically retrying "write" operations, as
// they are not idempotent. // they are not idempotent.
if !net.IsConnectionReset(err) || r.verb != "GET" { if r.verb != "GET" {
return err return err
} }
// For the purpose of retry, we set the artificial "retry-after" response. // For connection errors and apiserver shutdown errors retry.
// TODO: Should we clean the original response if it exists? if net.IsConnectionReset(err) || net.IsConnectionRefused(err) {
resp = &http.Response{ // For the purpose of retry, we set the artificial "retry-after" response.
StatusCode: http.StatusInternalServerError, // TODO: Should we clean the original response if it exists?
Header: http.Header{"Retry-After": []string{"1"}}, resp = &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte{})), StatusCode: http.StatusInternalServerError,
Header: http.Header{"Retry-After": []string{"1"}},
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
}
} else {
return err
} }
} }