Skip to content

Commit

Permalink
vendor: patch GOAWAY retry fix on v0.45.1 of google cloud SDK
Browse files Browse the repository at this point in the history
Patches v0.45.1 of `cloud.google.com/go` with
googleapis/google-cloud-go#4226.
  • Loading branch information
adityamaru committed Jun 23, 2021
1 parent 55c05c7 commit 8eebed7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
20 changes: 9 additions & 11 deletions cloud.google.com/go/storage/reader.go
Expand Up @@ -23,7 +23,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -130,6 +129,11 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64)
// Define a function that initiates a Read with offset and length, assuming we
// have already read seen bytes.
reopen := func(seen int64) (*http.Response, error) {
// If the context has already expired, return immediately without making a
// call.
if err := ctx.Err(); err != nil {
return nil, err
}
start := offset + seen
if length < 0 && start < 0 {
req.Header.Set("Range", fmt.Sprintf("bytes=%d", start))
Expand Down Expand Up @@ -337,11 +341,12 @@ func (r *Reader) readWithRetry(p []byte) (int, error) {
m, err := r.body.Read(p[n:])
n += m
r.seen += int64(m)
if !shouldRetryRead(err) {
if err == nil || err == io.EOF {
return n, err
}
// Read failed, but we will try again. Send a ranged read request that takes
// into account the number of bytes we've already seen.
// Read failed (likely due to connection issues), but we will try to reopen
// the pipe and continue. Send a ranged read request that takes into account
// the number of bytes we've already seen.
res, err := r.reopen(r.seen)
if err != nil {
// reopen already retries
Expand All @@ -353,13 +358,6 @@ func (r *Reader) readWithRetry(p []byte) (int, error) {
return n, nil
}

func shouldRetryRead(err error) bool {
if err == nil {
return false
}
return strings.HasSuffix(err.Error(), "INTERNAL_ERROR") && strings.Contains(reflect.TypeOf(err).String(), "http2")
}

// Size returns the size of the object in bytes.
// The returned value is always the same and is not affected by
// calls to Read or Close.
Expand Down
3 changes: 2 additions & 1 deletion modules.txt
@@ -1,4 +1,4 @@
# cloud.google.com/go v0.45.1
# cloud.google.com/go v0.45.1 => github.com/cockroachdb/google-cloud-go v0.45.2-0.20210623224357-4fefe580b8d5
## explicit
cloud.google.com/go/compute/metadata
cloud.google.com/go/iam
Expand Down Expand Up @@ -1285,6 +1285,7 @@ vitess.io/vitess/go/vt/sqlparser
vitess.io/vitess/go/vt/sysvars
vitess.io/vitess/go/vt/vterrors
vitess.io/vitess/go/vt/vtgate/evalengine
# cloud.google.com/go => github.com/cockroachdb/google-cloud-go v0.45.2-0.20210623224357-4fefe580b8d5
# github.com/gogo/protobuf => github.com/cockroachdb/gogoproto v1.2.1-0.20210111172841-8b6737fea948
# github.com/grpc-ecosystem/grpc-gateway => github.com/cockroachdb/grpc-gateway v1.14.6-0.20200519165156-52697fc4a249
# github.com/olekukonko/tablewriter => github.com/cockroachdb/tablewriter v0.0.5-0.20200105123400-bd15540e8847
Expand Down

0 comments on commit 8eebed7

Please sign in to comment.