Skip to content

Commit

Permalink
chore(storage): remove Go 1.9 code (#4544)
Browse files Browse the repository at this point in the history
We no longer support Go 1.9 so the code removed here is dead
and build tags are no longer required.
  • Loading branch information
tritone committed Aug 3, 2021
1 parent c6de69c commit 0f3b6f6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 158 deletions.
56 changes: 0 additions & 56 deletions storage/go110.go

This file was deleted.

35 changes: 35 additions & 0 deletions storage/invoke.go
Expand Up @@ -16,9 +16,13 @@ package storage

import (
"context"
"io"
"net/url"
"strings"

"cloud.google.com/go/internal"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/googleapi"
)

// runWithRetry calls the function until it returns nil or a non-retryable error, or
Expand All @@ -35,3 +39,34 @@ func runWithRetry(ctx context.Context, call func() error) error {
return true, err
})
}

func shouldRetry(err error) bool {
if err == io.ErrUnexpectedEOF {
return true
}
switch e := err.(type) {
case *googleapi.Error:
// Retry on 429 and 5xx, according to
// https://cloud.google.com/storage/docs/exponential-backoff.
return e.Code == 429 || (e.Code >= 500 && e.Code < 600)
case *url.Error:
// Retry socket-level errors ECONNREFUSED and ENETUNREACH (from syscall).
// Unfortunately the error type is unexported, so we resort to string
// matching.
retriable := []string{"connection refused", "connection reset"}
for _, s := range retriable {
if strings.Contains(e.Error(), s) {
return true
}
}
case interface{ Temporary() bool }:
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
}
2 changes: 0 additions & 2 deletions storage/go110_test.go → storage/invoke_test.go
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build go1.10

package storage

import (
Expand Down
42 changes: 0 additions & 42 deletions storage/not_go110.go

This file was deleted.

58 changes: 0 additions & 58 deletions storage/not_go110_test.go

This file was deleted.

0 comments on commit 0f3b6f6

Please sign in to comment.