From 06497f830334d9c4ddf90eceb5de29a8d9ed47aa Mon Sep 17 00:00:00 2001 From: Yan Song Date: Wed, 5 Jun 2024 06:41:48 +0000 Subject: [PATCH] errdefs: add timeout case for NeedsRetryWithHTTP For some registry servers whose gateway has https on port 443 but does not forward the request to the registry server, an io timeout error occurs and we may need to fallback to http as well. Signed-off-by: Yan Song --- pkg/errdefs/errors.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/errdefs/errors.go b/pkg/errdefs/errors.go index 9c16850b..855fef26 100644 --- a/pkg/errdefs/errors.go +++ b/pkg/errdefs/errors.go @@ -21,7 +21,7 @@ var ( ErrSameTag = errors.New("ERR_SAME_TAG") ) -// IsErrHTTPResponseToHTTPSClient returns whether err is +// isErrHTTPResponseToHTTPSClient returns whether err is // "http: server gave HTTP response to HTTPS client" func isErrHTTPResponseToHTTPSClient(err error) bool { // The error string is unexposed as of Go 1.16, so we can't use `errors.Is`. @@ -30,15 +30,21 @@ func isErrHTTPResponseToHTTPSClient(err error) bool { return strings.Contains(err.Error(), unexposed) } -// IsErrConnectionRefused return whether err is +// isErrConnectionRefused return whether err is // "connect: connection refused" func isErrConnectionRefused(err error) bool { const errMessage = "connect: connection refused" return strings.Contains(err.Error(), errMessage) } +// isErrTimeout return whether err is "timeout" +func isErrTimeout(err error) bool { + const errMessage = "timeout" + return strings.Contains(err.Error(), errMessage) +} + func NeedsRetryWithHTTP(err error) bool { - return err != nil && (isErrHTTPResponseToHTTPSClient(err) || isErrConnectionRefused(err)) + return err != nil && (isErrHTTPResponseToHTTPSClient(err) || isErrConnectionRefused(err) || isErrTimeout(err)) } func isErrInconsistentNydusLayer(err error) bool {