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

#### Type of change

- [x] 🐛 Bugfix

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-05-05 13:00:09 -06:00 committed by GitHub
parent eab5510c03
commit ef2083bc20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -196,6 +196,10 @@ func (mw RetryMiddleware) Intercept(
return resp, stackReq(ctx, req, resp, err) 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 := backoff.NewExponentialBackOff()
exponentialBackOff.InitialInterval = mw.Delay exponentialBackOff.InitialInterval = mw.Delay
exponentialBackOff.Reset() exponentialBackOff.Reset()
@ -313,6 +317,12 @@ func (mw RetryMiddleware) isRetriableRespCode(ctx context.Context, resp *http.Re
return true 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 // not a status code, but the message itself might indicate a connectivity issue that
// can be retried independent of the status code. // can be retried independent of the status code.
return strings.Contains( return strings.Contains(