Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 76ae819

Browse files
authoredNov 10, 2022
Fix context.DeadlineExceeded comparison (#1488)
1 parent 353a117 commit 76ae819

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎internal/retry/retry.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package retry
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223

2324
"github.com/google/go-containerregistry/internal/retry/wait"
@@ -36,7 +37,7 @@ type temporary interface {
3637

3738
// IsTemporary returns true if err implements Temporary() and it returns true.
3839
func IsTemporary(err error) bool {
39-
if err == context.DeadlineExceeded {
40+
if errors.Is(err, context.DeadlineExceeded) {
4041
return false
4142
}
4243
if te, ok := err.(temporary); ok && te.Temporary() {

‎internal/retry/retry_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package retry
1717
import (
1818
"context"
1919
"fmt"
20+
"net/http"
21+
"net/url"
2022
"testing"
2123
)
2224

@@ -55,6 +57,14 @@ func TestRetry(t *testing.T) {
5557
predicate: IsTemporary,
5658
err: context.DeadlineExceeded,
5759
shouldRetry: false,
60+
}, {
61+
predicate: IsTemporary,
62+
err: &url.Error{
63+
Op: http.MethodPost,
64+
URL: "http://127.0.0.1:56520/v2/example/blobs/uploads/",
65+
Err: context.DeadlineExceeded,
66+
},
67+
shouldRetry: false,
5868
}} {
5969
// Make sure we retry 5 times if we shouldRetry.
6070
steps := 5

0 commit comments

Comments
 (0)
Please sign in to comment.