Retry connection reset by peer

This commit is contained in:
Wojciech Tyczynski
2016-12-20 14:41:18 +01:00
parent 6fd22784a4
commit 9a4828821d
3 changed files with 55 additions and 1 deletions

View File

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