Skip to content

Commit 06497f8

Browse files
committed
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 <[email protected]>
1 parent 479881d commit 06497f8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/errdefs/errors.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
ErrSameTag = errors.New("ERR_SAME_TAG")
2222
)
2323

24-
// IsErrHTTPResponseToHTTPSClient returns whether err is
24+
// isErrHTTPResponseToHTTPSClient returns whether err is
2525
// "http: server gave HTTP response to HTTPS client"
2626
func isErrHTTPResponseToHTTPSClient(err error) bool {
2727
// 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 {
3030
return strings.Contains(err.Error(), unexposed)
3131
}
3232

33-
// IsErrConnectionRefused return whether err is
33+
// isErrConnectionRefused return whether err is
3434
// "connect: connection refused"
3535
func isErrConnectionRefused(err error) bool {
3636
const errMessage = "connect: connection refused"
3737
return strings.Contains(err.Error(), errMessage)
3838
}
3939

40+
// isErrTimeout return whether err is "timeout"
41+
func isErrTimeout(err error) bool {
42+
const errMessage = "timeout"
43+
return strings.Contains(err.Error(), errMessage)
44+
}
45+
4046
func NeedsRetryWithHTTP(err error) bool {
41-
return err != nil && (isErrHTTPResponseToHTTPSClient(err) || isErrConnectionRefused(err))
47+
return err != nil && (isErrHTTPResponseToHTTPSClient(err) || isErrConnectionRefused(err) || isErrTimeout(err))
4248
}
4349

4450
func isErrInconsistentNydusLayer(err error) bool {

0 commit comments

Comments
 (0)