From ef898456d14592574235bb839514bd549e1007ba Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Wed, 9 Feb 2022 12:51:49 -0500 Subject: [PATCH] fix(gensupport): cover ChunkRetryDeadline edge case (#1430) Fix an edge case that I noticed when testing a very small ChunkRetryDeadline via the storage client. If the user chooses a deadline too short to send a single request for the chunk, we cause a failure so that resp and err are not both nil. --- internal/gensupport/resumable.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/gensupport/resumable.go b/internal/gensupport/resumable.go index ce4272509f6..0eae147fa92 100644 --- a/internal/gensupport/resumable.go +++ b/internal/gensupport/resumable.go @@ -155,6 +155,12 @@ func (rx *ResumableUpload) Upload(ctx context.Context) (resp *http.Response, err } return nil, err } + // This case is very unlikely but possible only if rx.ChunkRetryDeadline is + // set to a very small value, in which case no requests will be sent before + // the deadline. Return an error to avoid causing a panic. + if resp == nil { + return nil, fmt.Errorf("upload request to %v not sent, choose larger value for ChunkRetryDealine", rx.URI) + } return resp, nil } // Configure retryable error criteria.