additional middleware segfault protection (#3296)

gotta catch 'em all

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🐛 Bugfix

#### Issue(s)

* #3285

#### Test Plan

- [x] 💚 E2E
This commit is contained in:
Keepers 2023-05-03 16:10:27 -06:00 committed by GitHub
parent 7326730e0d
commit 6cc779eb1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -227,17 +227,24 @@ func (mw RetryMiddleware) retryRequest(
exponentialBackoff *backoff.ExponentialBackOff,
priorErr error,
) (*http.Response, error) {
ctx = clues.Add(ctx, "retry_count", executionCount)
status := "unknown_resp_status"
statusCode := -1
if resp != nil {
ctx = clues.Add(ctx, "prev_resp_status", resp.Status)
status = resp.Status
statusCode = resp.StatusCode
}
ctx = clues.Add(
ctx,
"prev_resp_status", status,
"retry_count", executionCount)
// only retry under certain conditions:
// 1, there was an error. 2, the resp and/or status code match retriable conditions.
// 3, the request is retriable.
// 4, we haven't hit our max retries already.
if (priorErr != nil || mw.isRetriableRespCode(ctx, resp, resp.StatusCode)) &&
if (priorErr != nil || mw.isRetriableRespCode(ctx, resp, statusCode)) &&
mw.isRetriableRequest(req) &&
executionCount < mw.MaxRetries {
executionCount++