diff --git a/storage/go.mod b/storage/go.mod index f131dfaeccd..8ce54669999 100644 --- a/storage/go.mod +++ b/storage/go.mod @@ -8,6 +8,7 @@ require ( github.com/google/go-cmp v0.5.5 github.com/googleapis/gax-go/v2 v2.0.5 golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 google.golang.org/api v0.45.0 google.golang.org/genproto v0.0.0-20210427215850-f767ed18ee4d google.golang.org/grpc v1.37.0 diff --git a/storage/go110.go b/storage/go110.go index 804d39fa936..3d0a8187841 100644 --- a/storage/go110.go +++ b/storage/go110.go @@ -43,10 +43,14 @@ func shouldRetry(err error) bool { return true } } - return false case interface{ Temporary() bool }: - return e.Temporary() - default: - return false + if e.Temporary() { + return true + } + } + // Unwrap is only supported in go1.13.x+ + if e, ok := err.(interface{ Unwrap() error }); ok { + return shouldRetry(e.Unwrap()) } + return false } diff --git a/storage/go110_test.go b/storage/go110_test.go index 9439bb6006d..c3d94d32a71 100644 --- a/storage/go110_test.go +++ b/storage/go110_test.go @@ -23,6 +23,8 @@ import ( "net/url" "testing" + "golang.org/x/xerrors" + "google.golang.org/api/googleapi" ) @@ -45,6 +47,8 @@ func TestInvoke(t *testing.T) { {2, &googleapi.Error{Code: 599}, &googleapi.Error{Code: 428}}, {1, &url.Error{Op: "blah", URL: "blah", Err: errors.New("connection refused")}, nil}, {1, io.ErrUnexpectedEOF, nil}, + {1, xerrors.Errorf("Test unwrapping of a temporary error: %w", &googleapi.Error{Code: 500}), nil}, + {0, xerrors.Errorf("Test unwrapping of a non-retriable error: %w", &googleapi.Error{Code: 400}), &googleapi.Error{Code: 400}}, } { counter := 0 call := func() error {