Skip to content

Commit b0d31a1

Browse files
authored
Retry on TOOMANYREQUESTS error from ECR (#750)
* Retry on TOOMANYREQUESTS error from ECR * use a set instead
1 parent 38ad4ec commit b0d31a1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/v1/remote/transport/error.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ func (e *Error) Temporary() bool {
8989
return false
9090
}
9191
for _, d := range e.Errors {
92-
// TODO: Include other error types.
93-
if d.Code != BlobUploadInvalidErrorCode {
92+
if _, ok := temporaryErrorCodes[d.Code]; !ok {
9493
return false
9594
}
9695
}
@@ -149,8 +148,15 @@ const (
149148
UnauthorizedErrorCode ErrorCode = "UNAUTHORIZED"
150149
DeniedErrorCode ErrorCode = "DENIED"
151150
UnsupportedErrorCode ErrorCode = "UNSUPPORTED"
151+
TooManyRequestsErrorCode ErrorCode = "TOOMANYREQUESTS"
152152
)
153153

154+
// TODO: Include other error types.
155+
var temporaryErrorCodes = map[ErrorCode]struct{}{
156+
BlobUploadInvalidErrorCode: struct{}{},
157+
TooManyRequestsErrorCode: struct{}{},
158+
}
159+
154160
// CheckError returns a structured error if the response status is not in codes.
155161
func CheckError(resp *http.Response, codes ...int) error {
156162
for _, code := range codes {

pkg/v1/remote/transport/error_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func TestTemporary(t *testing.T) {
5050
}},
5151
},
5252
retry: false,
53+
}, {
54+
error: &Error{
55+
Errors: []Diagnostic{{
56+
Code: TooManyRequestsErrorCode,
57+
}},
58+
},
59+
retry: true,
5360
}}
5461

5562
for _, test := range tests {

0 commit comments

Comments
 (0)