Skip to content

Commit 7038aee

Browse files
committed
fix issue
Signed-off-by: ChengyuZhu6 <[email protected]>
1 parent 0837936 commit 7038aee

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

pkg/cmd/image/ensure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func ensureOne(ctx context.Context, client *containerd.Client, rawRef string, ta
9999

100100
if err != nil {
101101
// In some circumstance (e.g. people just use 80 port to support pure http), the error will contain message like "dial tcp <port>: connection refused".
102-
if !errors.Is(err, http.ErrSchemeMismatch) && !errutil.IsErrConnectionRefused(err) {
102+
if !errors.Is(err, http.ErrSchemeMismatch) && !errutil.IsErrConnectionRefused(err) && !errutil.IsErrHTTPResponseToHTTPSClient(err) {
103103
return err
104104
}
105105
if options.InsecureRegistry {

pkg/errutil/errors_check.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ func IsErrConnectionRefused(err error) bool {
2424
const errMessage = "connect: connection refused"
2525
return strings.Contains(err.Error(), errMessage)
2626
}
27+
28+
// IsErrHTTPResponseToHTTPSClient return whether err is
29+
// "http: server gave HTTP response to HTTPS client"
30+
func IsErrHTTPResponseToHTTPSClient(err error) bool {
31+
const errMessage = "server gave HTTP response to HTTPS client"
32+
return strings.Contains(err.Error(), errMessage)
33+
}

pkg/imgutil/transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func executeTransferWithRetry(ctx context.Context, client *containerd.Client, pa
173173

174174
transferErr := doTransfer(false)
175175
if transferErr != nil {
176-
if errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr) {
176+
if errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr) || errutil.IsErrHTTPResponseToHTTPSClient(transferErr) {
177177
if gOptions.InsecureRegistry {
178178
log.G(ctx).WithError(transferErr).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", parsedReference.Domain)
179179
transferErr = doTransfer(true)

0 commit comments

Comments
 (0)