Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errdefs: add timeout case for NeedsRetryWithHTTP #290

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/errdefs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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 {
Expand Down
Loading