Skip to content

Commit

Permalink
Retry on TOOMANYREQUESTS error from ECR (#750)
Browse files Browse the repository at this point in the history
* Retry on TOOMANYREQUESTS error from ECR

* use a set instead
  • Loading branch information
jchorl committed Aug 4, 2020
1 parent 38ad4ec commit b0d31a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/v1/remote/transport/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (e *Error) Temporary() bool {
return false
}
for _, d := range e.Errors {
// TODO: Include other error types.
if d.Code != BlobUploadInvalidErrorCode {
if _, ok := temporaryErrorCodes[d.Code]; !ok {
return false
}
}
Expand Down Expand Up @@ -149,8 +148,15 @@ const (
UnauthorizedErrorCode ErrorCode = "UNAUTHORIZED"
DeniedErrorCode ErrorCode = "DENIED"
UnsupportedErrorCode ErrorCode = "UNSUPPORTED"
TooManyRequestsErrorCode ErrorCode = "TOOMANYREQUESTS"
)

// TODO: Include other error types.
var temporaryErrorCodes = map[ErrorCode]struct{}{
BlobUploadInvalidErrorCode: struct{}{},
TooManyRequestsErrorCode: struct{}{},
}

// 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
7 changes: 7 additions & 0 deletions pkg/v1/remote/transport/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func TestTemporary(t *testing.T) {
}},
},
retry: false,
}, {
error: &Error{
Errors: []Diagnostic{{
Code: TooManyRequestsErrorCode,
}},
},
retry: true,
}}

for _, test := range tests {
Expand Down

0 comments on commit b0d31a1

Please sign in to comment.