Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry on 502 return code #124

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/token/token-util/token-util.go
Original file line number Diff line number Diff line change
@@ -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
}

15 changes: 12 additions & 3 deletions pkg/token/token-util/token-util_test.go
Original file line number Diff line number Diff line change
@@ -158,14 +158,23 @@ func TestDoRetries(t *testing.T) {
responseStatus: http.StatusTooManyRequests,
},
{
name: "status 502 no retry",
name: "status 502",
call: func() (*http.Response, error) {
totalRetries++

return &http.Response{StatusCode: http.StatusBadGateway}, nil
},
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)