From b1f8dd0c567a26c78b588432a14dcaca3987aae2 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 5 Sep 2024 04:00:20 -0700 Subject: [PATCH] Retry on internal HTTP context cancellations (#1998) Fixes #1997 --- api.go | 2 +- retry.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index a019403c4..1d6b66502 100644 --- a/api.go +++ b/api.go @@ -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 } diff --git a/retry.go b/retry.go index 5ddcad897..d15eb5901 100644 --- a/retry.go +++ b/retry.go @@ -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()