From 8bb11ceae3f5e745355382efc2a2a0b4d4ca3dd3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Aug 2025 06:20:23 +0000 Subject: [PATCH] chore(deps): Bump google.golang.org/api Bumps [google.golang.org/api](https://github.com/googleapis/google-api-go-client) from 0.244.0 to 0.246.0. - [Release notes](https://github.com/googleapis/google-api-go-client/releases) - [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md) - [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.244.0...v0.246.0) --- updated-dependencies: - dependency-name: google.golang.org/api dependency-version: 0.246.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- ci/resources/stemcell-version-bump/go.mod | 2 +- ci/resources/stemcell-version-bump/go.sum | 4 +- .../api/internal/gensupport/resumable.go | 98 +++++++++++++------ .../google.golang.org/api/internal/version.go | 2 +- .../stemcell-version-bump/vendor/modules.txt | 2 +- 5 files changed, 73 insertions(+), 35 deletions(-) diff --git a/ci/resources/stemcell-version-bump/go.mod b/ci/resources/stemcell-version-bump/go.mod index dc9f9204e..476f7788e 100644 --- a/ci/resources/stemcell-version-bump/go.mod +++ b/ci/resources/stemcell-version-bump/go.mod @@ -7,7 +7,7 @@ toolchain go1.24.1 require ( cloud.google.com/go/storage v1.56.0 github.com/stretchr/testify v1.10.0 - google.golang.org/api v0.244.0 + google.golang.org/api v0.246.0 ) require ( diff --git a/ci/resources/stemcell-version-bump/go.sum b/ci/resources/stemcell-version-bump/go.sum index 31c45afff..7b69f1672 100644 --- a/ci/resources/stemcell-version-bump/go.sum +++ b/ci/resources/stemcell-version-bump/go.sum @@ -115,8 +115,8 @@ golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= -google.golang.org/api v0.244.0 h1:lpkP8wVibSKr++NCD36XzTk/IzeKJ3klj7vbj+XU5pE= -google.golang.org/api v0.244.0/go.mod h1:dMVhVcylamkirHdzEBAIQWUCgqY885ivNeZYd7VAVr8= +google.golang.org/api v0.246.0 h1:H0ODDs5PnMZVZAEtdLMn2Ul2eQi7QNjqM2DIFp8TlTM= +google.golang.org/api v0.246.0/go.mod h1:dMVhVcylamkirHdzEBAIQWUCgqY885ivNeZYd7VAVr8= google.golang.org/genproto v0.0.0-20250603155806-513f23925822 h1:rHWScKit0gvAPuOnu87KpaYtjK5zBMLcULh7gxkCXu4= google.golang.org/genproto v0.0.0-20250603155806-513f23925822/go.mod h1:HubltRL7rMh0LfnQPkMH4NPDFEWp0jw3vixw7jEM53s= google.golang.org/genproto/googleapis/api v0.0.0-20250721164621-a45f3dfb1074 h1:mVXdvnmR3S3BQOqHECm9NGMjYiRtEvDYcqAqedTXY6s= diff --git a/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/gensupport/resumable.go b/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/gensupport/resumable.go index 143a48923..91108d327 100644 --- a/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/gensupport/resumable.go +++ b/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/gensupport/resumable.go @@ -127,34 +127,65 @@ func (rx *ResumableUpload) reportProgress(old, updated int64) { } // transferChunk performs a single HTTP request to upload a single chunk. +// It uses a goroutine to perform the upload and a timer to enforce ChunkTransferTimeout. func (rx *ResumableUpload) transferChunk(ctx context.Context, chunk io.Reader, off, size int64, done bool) (*http.Response, error) { - // rCtx is derived from a context with a defined ChunkTransferTimeout with non-zero value. - // If a particular request exceeds this transfer time for getting response, the rCtx deadline will be exceeded, - // triggering a retry of the request. - var rCtx context.Context - var cancel context.CancelFunc - - rCtx = ctx - if rx.ChunkTransferTimeout != 0 { - rCtx, cancel = context.WithTimeout(ctx, rx.ChunkTransferTimeout) - defer cancel() + // If no timeout is specified, perform the request synchronously without a timer. + if rx.ChunkTransferTimeout == 0 { + res, err := rx.doUploadRequest(ctx, chunk, off, size, done) + if err != nil { + return res, err + } + return res, nil } - res, err := rx.doUploadRequest(rCtx, chunk, off, size, done) - if err != nil { - return res, err - } + // Start a timer for the ChunkTransferTimeout duration. + timer := time.NewTimer(rx.ChunkTransferTimeout) - // We sent "X-GUploader-No-308: yes" (see comment elsewhere in - // this file), so we don't expect to get a 308. - if res.StatusCode == 308 { - return nil, errors.New("unexpected 308 response status code") + // A struct to hold the result from the goroutine. + type uploadResult struct { + res *http.Response + err error } - if res.StatusCode == http.StatusOK { - rx.reportProgress(off, off+int64(size)) + // A buffered channel to receive the result of the upload. + resultCh := make(chan uploadResult, 1) + + // Create a cancellable context for the upload request. This allows us to + // abort the request if the timer fires first. + rCtx, cancel := context.WithCancel(ctx) + // NOTE: We do NOT use `defer cancel()` here. The context must remain valid + // for the caller to read the response body of a successful request. + // Cancellation is handled manually on timeout paths. + + // Starting the chunk upload in parallel. + go func() { + res, err := rx.doUploadRequest(rCtx, chunk, off, size, done) + resultCh <- uploadResult{res: res, err: err} + }() + + // Wait for timer to fire or result channel to have the uploadResult or ctx to be cancelled. + select { + // Note: Calling cancel() will guarantee that the goroutine finishes, + // so these two cases will never block forever on draining the resultCh. + case <-ctx.Done(): + // Context is cancelled for the overall upload. + cancel() + // Drain resultCh. + <-resultCh + return nil, ctx.Err() + case <-timer.C: + // Chunk Transfer timer fired before resultCh so we return context.DeadlineExceeded. + cancel() + // Drain resultCh. + <-resultCh + return nil, context.DeadlineExceeded + case result := <-resultCh: + // Handle the result from the upload. + if result.err != nil { + return result.res, result.err + } + return result.res, nil } - return res, nil } // uploadChunkWithRetries attempts to upload a single chunk, with retries @@ -164,14 +195,14 @@ func (rx *ResumableUpload) uploadChunkWithRetries(ctx context.Context, chunk io. shouldRetry := rx.Retry.errorFunc() // Configure single chunk retry deadline. - retryDeadline := defaultRetryDeadline + chunkRetryDeadline := defaultRetryDeadline if rx.ChunkRetryDeadline != 0 { - retryDeadline = rx.ChunkRetryDeadline + chunkRetryDeadline = rx.ChunkRetryDeadline } // Each chunk gets its own initialized-at-zero backoff and invocation ID. bo := rx.Retry.backoff() - quitAfterTimer := time.NewTimer(retryDeadline) + quitAfterTimer := time.NewTimer(chunkRetryDeadline) defer quitAfterTimer.Stop() rx.attempts = 1 rx.invocationID = uuid.New().String() @@ -184,20 +215,20 @@ func (rx *ResumableUpload) uploadChunkWithRetries(ctx context.Context, chunk io. for { // Wait for the backoff period, unless the context is canceled or the // retry deadline is hit. - pauseTimer := time.NewTimer(pause) + backoffPauseTimer := time.NewTimer(pause) select { case <-ctx.Done(): - pauseTimer.Stop() + backoffPauseTimer.Stop() if err == nil { err = ctx.Err() } return resp, err - case <-pauseTimer.C: + case <-backoffPauseTimer.C: case <-quitAfterTimer.C: - pauseTimer.Stop() + backoffPauseTimer.Stop() return resp, err } - pauseTimer.Stop() + backoffPauseTimer.Stop() // Check for context cancellation or timeout once more. If more than one // case in the select statement above was satisfied at the same time, Go @@ -233,6 +264,11 @@ func (rx *ResumableUpload) uploadChunkWithRetries(ctx context.Context, chunk io. if resp != nil { status = resp.StatusCode } + // We sent "X-GUploader-No-308: yes" (see comment elsewhere in + // this file), so we don't expect to get a 308. + if status == 308 { + return nil, errors.New("unexpected 308 response status code") + } // Chunk upload should be retried if the ChunkTransferTimeout is non-zero and err is context deadline exceeded // or we encounter a retryable error. if (rx.ChunkTransferTimeout != 0 && errors.Is(err, context.DeadlineExceeded)) || shouldRetry(status, err) { @@ -283,7 +319,9 @@ func (rx *ResumableUpload) Upload(ctx context.Context) (*http.Response, error) { if resp == nil { return nil, fmt.Errorf("upload request to %v not sent, choose larger value for ChunkRetryDeadline", rx.URI) } - + if resp.StatusCode == http.StatusOK { + rx.reportProgress(off, off+int64(size)) + } if statusResumeIncomplete(resp) { // The upload is not yet complete, but the server has acknowledged this chunk. // We don't have anything to do with the response body. diff --git a/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/version.go b/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/version.go index 11a0db6e5..9ed9684f8 100644 --- a/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/version.go +++ b/ci/resources/stemcell-version-bump/vendor/google.golang.org/api/internal/version.go @@ -5,4 +5,4 @@ package internal // Version is the current tagged release of the library. -const Version = "0.244.0" +const Version = "0.246.0" diff --git a/ci/resources/stemcell-version-bump/vendor/modules.txt b/ci/resources/stemcell-version-bump/vendor/modules.txt index b2a62e947..69de513f9 100644 --- a/ci/resources/stemcell-version-bump/vendor/modules.txt +++ b/ci/resources/stemcell-version-bump/vendor/modules.txt @@ -305,7 +305,7 @@ golang.org/x/text/unicode/norm # golang.org/x/time v0.12.0 ## explicit; go 1.23.0 golang.org/x/time/rate -# google.golang.org/api v0.244.0 +# google.golang.org/api v0.246.0 ## explicit; go 1.23.0 google.golang.org/api/googleapi google.golang.org/api/googleapi/transport