From a832630e295b8189514f9c0f81678fbf940fbb97 Mon Sep 17 00:00:00 2001 From: Eamonn O'Toole Date: Wed, 9 Oct 2024 14:48:33 +0100 Subject: [PATCH] Add retry on 502 return code In this PR we add the 502 (Bad Gateway) to the list of http return codes that will result in a retry. This is to alleviate errors seen in some runtime environments. Signed-off-by: Eamonn O'Toole --- pkg/token/token-util/token-util.go | 5 +++-- pkg/token/token-util/token-util_test.go | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/token/token-util/token-util.go b/pkg/token/token-util/token-util.go index eb6853c..2e7e90b 100644 --- a/pkg/token/token-util/token-util.go +++ b/pkg/token/token-util/token-util.go @@ -1,4 +1,4 @@ -// (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP package tokenutil @@ -134,7 +134,8 @@ func ManageHTTPErrorCodes(resp *http.Response, clientID string) error { } func isStatusRetryable(statusCode int) bool { - if statusCode == http.StatusInternalServerError || statusCode == http.StatusTooManyRequests { + if statusCode == http.StatusInternalServerError || statusCode == http.StatusTooManyRequests || + statusCode == http.StatusBadGateway { return true } diff --git a/pkg/token/token-util/token-util_test.go b/pkg/token/token-util/token-util_test.go index 65c3bfa..5a56f64 100644 --- a/pkg/token/token-util/token-util_test.go +++ b/pkg/token/token-util/token-util_test.go @@ -158,7 +158,7 @@ func TestDoRetries(t *testing.T) { responseStatus: http.StatusTooManyRequests, }, { - name: "status 502 no retry", + name: "status 502", call: func() (*http.Response, error) { totalRetries++ @@ -166,6 +166,15 @@ func TestDoRetries(t *testing.T) { }, responseStatus: http.StatusBadGateway, }, + { + name: "status 403 no retry", + call: func() (*http.Response, error) { + totalRetries++ + + return &http.Response{StatusCode: http.StatusForbidden}, nil + }, + responseStatus: http.StatusForbidden, + }, { name: "no url", call: func() (*http.Response, error) { @@ -184,8 +193,8 @@ func TestDoRetries(t *testing.T) { } else { assert.Equal(t, tc.responseStatus, resp.StatusCode) - // only 429 and 500 status codes should retry - if tc.responseStatus == http.StatusBadGateway { + // only 429, 500 and 502 status codes should retry + if tc.responseStatus == http.StatusForbidden { assert.Equal(t, 1, totalRetries) } else { assert.Equal(t, 2, totalRetries)