Skip to content

Commit

Permalink
feat: add transfer timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Tulsishah committed Nov 11, 2024
1 parent 1a33f93 commit 46290c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ type openWriterParams struct {
chunkSize int
// chunkRetryDeadline - see `Writer.ChunkRetryDeadline`.
// Optional.
chunkRetryDeadline time.Duration
chunkRetryDeadline time.Duration
chunkTransferTimeout time.Duration

// Object/request properties

Expand Down
4 changes: 3 additions & 1 deletion storage/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestIndefiniteRetries(t *testing.T) {
// mismatched_content_start (Invalid request. According to the Content-Range header,
// the upload offset is 1082130432 byte(s), which exceeds already uploaded size of 0 byte(s).)
errStr := fmt.Sprintf("mismatched_content_start (Invalid request. According to the Content-Range header,"+
"the upload offset is %s byte(s), which exceeds already uploaded size of 0 byte(s).)\n%s", start, r.Header["Content-Range"])
"the upload offset is %s byte(s), which exceeds already uploaded size of 0 byte(s).)\n%s", start, r.Header["Content-Range"])
http.Error(w, errStr, http.StatusServiceUnavailable)
return
}
Expand Down Expand Up @@ -137,6 +137,8 @@ func TestIndefiniteRetries(t *testing.T) {
// Use a shorter retry deadline to speed up the test.
w.ChunkRetryDeadline = time.Second

w.ChunkTransferTimeOut = time.Second

for i := 0; i < maxFileSize; {
nowStr := time.Now().Format(time.RFC3339Nano)
n, err := fmt.Fprintf(w, "%s", nowStr)
Expand Down
13 changes: 13 additions & 0 deletions storage/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ type Writer struct {
// cancellation.
ChunkRetryDeadline time.Duration

// ChunkTransferTimeOut sets a per-chunk retry transfer timeout for multi-chunk
// resumable uploads.
//
// For uploads of larger files, the Writer will attempt to retry if the
// request to upload a particular chunk stalls for some time.
// If a single chunk has been attempting to upload for longer than this
// deadline and the request fails, it will be retried. The default value
// is 8s. Users may want to pick a longer deadline if they are using larger
// values for ChunkSize or if they expect to have a slow or unreliable
// internet connection.
ChunkTransferTimeOut time.Duration

// ForceEmptyContentType is an optional parameter that is used to disable
// auto-detection of Content-Type. By default, if a blank Content-Type
// is provided, then gax.DetermineContentType is called to sniff the type.
Expand Down Expand Up @@ -188,6 +200,7 @@ func (w *Writer) openWriter() (err error) {
ctx: w.ctx,
chunkSize: w.ChunkSize,
chunkRetryDeadline: w.ChunkRetryDeadline,
chunkTransferTimeout: w.ChunkTransferTimeOut,
bucket: w.o.bucket,
attrs: &w.ObjectAttrs,
conds: w.o.conds,
Expand Down

0 comments on commit 46290c0

Please sign in to comment.