Skip to content

Commit 002e404

Browse files
authored
convertor: Retry on 5xx errors (#19)
**What this PR does / why we need it**: Also retry on 5xx errors. Occasionally we get various gateway errors or just 500 errors, the retry logic should apply to these too. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Please check the following list**: - [ ] Does the affected code have corresponding tests, e.g. unit test, E2E test? - [ ] Does this change require a documentation update? - [ ] Does this introduce breaking changes that would require an announcement or bumping the major version? - [ ] Do all new files have an appropriate license header? <!-- If this is a security issue, please do not discuss on GitHub. Please report any suspected or confirmed security issues directly to https://github.com/containerd/accelerated-container-image/blob/main/MAINTAINERS. -->
1 parent 21a2ad8 commit 002e404

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

cmd/convertor/builder/builder_utils.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/containerd/containerd/v2/core/images"
3636
"github.com/containerd/containerd/v2/core/remotes"
3737
"github.com/containerd/containerd/v2/core/remotes/docker"
38+
remoteerrors "github.com/containerd/containerd/v2/core/remotes/errors"
3839
"github.com/containerd/containerd/v2/pkg/archive/compression"
3940
"github.com/containerd/continuity"
4041
"github.com/containerd/errdefs"
@@ -54,18 +55,33 @@ func isRetryableError(err error) bool {
5455
return false
5556
}
5657

57-
// Check for containerd docker error types
58-
var dockerErr *docker.Error
59-
if errors.As(err, &dockerErr) {
60-
switch dockerErr.Code {
61-
case docker.ErrorCodeTooManyRequests:
62-
return true
63-
case docker.ErrorCodeUnavailable:
58+
// Registry may return multiple errors in one response (docker.Errors)
59+
var regErrs docker.Errors
60+
if errors.As(err, &regErrs) {
61+
for _, e := range regErrs {
62+
switch v := e.(type) {
63+
case docker.ErrorCode:
64+
if v == docker.ErrorCodeTooManyRequests || v == docker.ErrorCodeUnavailable || v == docker.ErrorCodeUnknown {
65+
return true
66+
}
67+
case docker.Error:
68+
if v.Code == docker.ErrorCodeTooManyRequests || v.Code == docker.ErrorCodeUnavailable || v.Code == docker.ErrorCodeUnknown {
69+
return true
70+
}
71+
}
72+
}
73+
}
74+
75+
// Unexpected HTTP status codes (e.g., 429 or 5xx)
76+
var us remoteerrors.ErrUnexpectedStatus
77+
if errors.As(err, &us) {
78+
if us.StatusCode == 429 || (us.StatusCode >= 500 && us.StatusCode <= 599) {
6479
return true
65-
default:
66-
return false
6780
}
68-
} else if err, ok := err.(net.Error); ok && err.Timeout() {
81+
}
82+
83+
// Network timeouts
84+
if ne, ok := err.(net.Error); ok && ne.Timeout() {
6985
return true
7086
}
7187

cmd/convertor/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func init() {
396396
rootCmd.Flags().IntVar(&concurrencyLimit, "concurrency-limit", 4, "the number of manifests that can be built at the same time, used for multi-arch images, 0 means no limit")
397397
rootCmd.Flags().BoolVar(&disableSparse, "disable-sparse", false, "disable sparse file for overlaybd")
398398
rootCmd.Flags().BoolVar(&referrer, "referrer", false, "push converted manifests with subject, note '--oci' will be enabled automatically if '--referrer' is set, cause the referrer must be in OCI format.")
399-
rootCmd.Flags().IntVar(&retryCount, "retry-count", 5, "number of retries for registry upload operations when encountering 429 rate limiting")
399+
rootCmd.Flags().IntVar(&retryCount, "retry-count", 5, "number of retries for registry upload operations when encountering 429 rate limiting or 5xx errors")
400400

401401
// tar import/export
402402
rootCmd.Flags().StringVar(&importTar, "import-tar", "", "import image from tar file (OCI layout format)")

0 commit comments

Comments
 (0)