Skip to content

Commit

Permalink
Retry on internal HTTP context cancellations
Browse files Browse the repository at this point in the history
Fixes #1997
  • Loading branch information
klauspost committed Sep 5, 2024
1 parent 48517d8 commit b81adb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ
// Initiate the request.
res, err = c.do(req)
if err != nil {
if isRequestErrorRetryable(err) {
if isRequestErrorRetryable(ctx, err) {
// Retry the request
continue
}
Expand Down
5 changes: 3 additions & 2 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ func isHTTPStatusRetryable(httpStatusCode int) (ok bool) {
}

// For now, all http Do() requests are retriable except some well defined errors
func isRequestErrorRetryable(err error) bool {
func isRequestErrorRetryable(ctx context.Context, err error) bool {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return false
// Retry if internal timeout in the HTTP call.
return ctx.Err() == nil
}
if ue, ok := err.(*url.Error); ok {
e := ue.Unwrap()
Expand Down

0 comments on commit b81adb2

Please sign in to comment.