From ef2083bc200a67cfdd596a4fabf603ad29ff371d Mon Sep 17 00:00:00 2001 From: Keepers Date: Fri, 5 May 2023 13:00:09 -0600 Subject: [PATCH] do not dump 2xx bodies in retry checker (#3332) Don't dump the response body if there was no error as the requested data could be multiple GB in size in some cases #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :bug: Bugfix #### Test Plan - [x] :zap: Unit test - [x] :green_heart: E2E --- src/internal/connector/graph/middleware.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/internal/connector/graph/middleware.go b/src/internal/connector/graph/middleware.go index f9701965e..b1d4ad99f 100644 --- a/src/internal/connector/graph/middleware.go +++ b/src/internal/connector/graph/middleware.go @@ -196,6 +196,10 @@ func (mw RetryMiddleware) Intercept( return resp, stackReq(ctx, req, resp, err) } + if resp != nil && resp.StatusCode/100 != 4 && resp.StatusCode/100 != 5 { + return resp, err + } + exponentialBackOff := backoff.NewExponentialBackOff() exponentialBackOff.InitialInterval = mw.Delay exponentialBackOff.Reset() @@ -313,6 +317,12 @@ func (mw RetryMiddleware) isRetriableRespCode(ctx context.Context, resp *http.Re return true } + // prevent the body dump below in case of a 2xx response. + // There's no reason to check the body on a healthy status. + if code/100 != 4 && code/100 != 5 { + return false + } + // not a status code, but the message itself might indicate a connectivity issue that // can be retried independent of the status code. return strings.Contains(