Skip to content

Commit

Permalink
Fix context.DeadlineExceeded comparison (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-lowman-dd authored Nov 10, 2022
1 parent 353a117 commit 76ae819
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package retry

import (
"context"
"errors"
"fmt"

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

// IsTemporary returns true if err implements Temporary() and it returns true.
func IsTemporary(err error) bool {
if err == context.DeadlineExceeded {
if errors.Is(err, context.DeadlineExceeded) {
return false
}
if te, ok := err.(temporary); ok && te.Temporary() {
Expand Down
10 changes: 10 additions & 0 deletions internal/retry/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package retry
import (
"context"
"fmt"
"net/http"
"net/url"
"testing"
)

Expand Down Expand Up @@ -55,6 +57,14 @@ func TestRetry(t *testing.T) {
predicate: IsTemporary,
err: context.DeadlineExceeded,
shouldRetry: false,
}, {
predicate: IsTemporary,
err: &url.Error{
Op: http.MethodPost,
URL: "http://127.0.0.1:56520/v2/example/blobs/uploads/",
Err: context.DeadlineExceeded,
},
shouldRetry: false,
}} {
// Make sure we retry 5 times if we shouldRetry.
steps := 5
Expand Down

0 comments on commit 76ae819

Please sign in to comment.