Skip to content

Commit 0f3b6f6

Browse files
authored
chore(storage): remove Go 1.9 code (#4544)
We no longer support Go 1.9 so the code removed here is dead and build tags are no longer required.
1 parent c6de69c commit 0f3b6f6

File tree

5 files changed

+35
-158
lines changed

5 files changed

+35
-158
lines changed

storage/go110.go

-56
This file was deleted.

storage/invoke.go

+35
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ package storage
1616

1717
import (
1818
"context"
19+
"io"
20+
"net/url"
21+
"strings"
1922

2023
"cloud.google.com/go/internal"
2124
gax "github.com/googleapis/gax-go/v2"
25+
"google.golang.org/api/googleapi"
2226
)
2327

2428
// runWithRetry calls the function until it returns nil or a non-retryable error, or
@@ -35,3 +39,34 @@ func runWithRetry(ctx context.Context, call func() error) error {
3539
return true, err
3640
})
3741
}
42+
43+
func shouldRetry(err error) bool {
44+
if err == io.ErrUnexpectedEOF {
45+
return true
46+
}
47+
switch e := err.(type) {
48+
case *googleapi.Error:
49+
// Retry on 429 and 5xx, according to
50+
// https://cloud.google.com/storage/docs/exponential-backoff.
51+
return e.Code == 429 || (e.Code >= 500 && e.Code < 600)
52+
case *url.Error:
53+
// Retry socket-level errors ECONNREFUSED and ENETUNREACH (from syscall).
54+
// Unfortunately the error type is unexported, so we resort to string
55+
// matching.
56+
retriable := []string{"connection refused", "connection reset"}
57+
for _, s := range retriable {
58+
if strings.Contains(e.Error(), s) {
59+
return true
60+
}
61+
}
62+
case interface{ Temporary() bool }:
63+
if e.Temporary() {
64+
return true
65+
}
66+
}
67+
// Unwrap is only supported in go1.13.x+
68+
if e, ok := err.(interface{ Unwrap() error }); ok {
69+
return shouldRetry(e.Unwrap())
70+
}
71+
return false
72+
}

storage/go110_test.go storage/invoke_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// +build go1.10
16-
1715
package storage
1816

1917
import (

storage/not_go110.go

-42
This file was deleted.

storage/not_go110_test.go

-58
This file was deleted.

0 commit comments

Comments
 (0)