Skip to content

Commit

Permalink
Retry registry access on some server errors. (#901)
Browse files Browse the repository at this point in the history
Sometimes the error is on proxy level, but it still will be beneficial
to retry it.

Co-authored-by: Kuba Skiepko <skiepko@google.com>
  • Loading branch information
kramarz and kramarz authored Jan 7, 2021
1 parent d1ffc8b commit 3b7741e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/v1/remote/transport/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (e *Error) responseErr() string {
// Temporary returns whether the request that preceded the error is temporary.
func (e *Error) Temporary() bool {
if len(e.Errors) == 0 {
return false
_, ok := temporaryStatusCodes[e.StatusCode]
return ok
}
for _, d := range e.Errors {
if _, ok := temporaryErrorCodes[d.Code]; !ok {
Expand Down Expand Up @@ -161,6 +162,12 @@ var temporaryErrorCodes = map[ErrorCode]struct{}{
TooManyRequestsErrorCode: {},
}

var temporaryStatusCodes = map[int]struct{}{
http.StatusInternalServerError: {},
http.StatusBadGateway: {},
http.StatusServiceUnavailable: {},
}

// CheckError returns a structured error if the response status is not in codes.
func CheckError(resp *http.Response, codes ...int) error {
for _, code := range codes {
Expand Down
5 changes: 5 additions & 0 deletions pkg/v1/remote/transport/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func TestTemporary(t *testing.T) {
}},
},
retry: true,
}, {
error: &Error{
StatusCode: http.StatusInternalServerError,
},
retry: true,
}}

for _, test := range tests {
Expand Down

0 comments on commit 3b7741e

Please sign in to comment.