Skip to content

Commit

Permalink
google: Client retries timeouts
Browse files Browse the repository at this point in the history
Previously, a net.Error was retried only if it was flagged as Temporary.
Now it is also retried if it is flagged as a Timeout.
  • Loading branch information
evandbrown committed Jan 26, 2019
1 parent 5bc75ac commit b90a761
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/bosh-google-cpi/google/client/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func (rt *RetryTransport) try(req *http.Request) (resp *http.Response, err error
return
}
}

var sleep func()
for try := 0; try <= rt.MaxRetries; try++ {
r := bytes.NewReader(body)
req.Body = ioutil.NopCloser(r)
resp, err = rt.Base.RoundTrip(req)

sleep := func() {
sleep = func() {
d := rt.FirstRetrySleep << uint64(try)
rt.logger.Info(retryLogTag, "Retrying request (%d/%d) after %s", try, rt.MaxRetries, d)
time.Sleep(d)
Expand All @@ -64,12 +64,15 @@ func (rt *RetryTransport) try(req *http.Request) (resp *http.Response, err error
// Retry on net.Error
switch err.(type) {
case net.Error:
if !err.(net.Error).Temporary() {
return
if err.(net.Error).Temporary() || err.(net.Error).Timeout() {
rt.logger.Info(retryLogTag, "net.Error is retryable: %s", err.Error())
sleep()
continue
}
sleep()
continue
rt.logger.Info(retryLogTag, "net.Error was not retryable: %s", err.Error())
return
case error:
rt.logger.Info(retryLogTag, "Error was not retryable: %s", err.Error())
return
}

Expand Down

0 comments on commit b90a761

Please sign in to comment.