Skip to content

fix(storage): cancel uploads when source reads fail - #5264

Open
singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/cancel-failed-object-uploads
Open

singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/cancel-failed-object-uploads

Conversation

@singh4jitendra

Copy link
Copy Markdown
Contributor

Description

If CreateObject cannot finish reading its input, it returns the source error without closing the SDK writer. The writer can remain active after the call has returned.

Give each upload its own context and cancel it when the call exits. This releases the writer on failure without calling Close, which could finalize partial data. The caller's context and the original source error are preserved.

The regression test writes a small partial checkpoint, injects a read error and checks that the actual SDK writer is canceled. This concerns the bucket adapter, not the new unbuffered handler's abort path in #5232.

Link to the issue in case of a bug fix.

Fixes #5259

Testing details

Go 1.27.4, Linux under WSL.

  1. Manual -
    • The local Linux filesystem became read-only during this batch, so the full build ran from writable task storage with CGO_ENABLED=0 and a longer local lint budget:
      printf 'lint: vet\n\tgolangci-lint run -E=unused --timeout 10m0s --new-from-rev=master\n' | make -f Makefile -f - build - passed with 0 lint issues. No build checks were skipped.
  2. Unit tests -
    • go test -mod=readonly -p 1 -count=1 -timeout=30s -run '^TestCreateObjectCancelsUploadAfterSourceError$' ./internal/storage - failed as expected before the fix because the SDK writer remained active.
    • go test -mod=readonly -p 1 -count=20 -race -timeout=90s -run '^TestCreateObjectCancelsUploadAfterSourceError$' ./internal/storage - passed all 20 repetitions.
    • go test -mod=readonly -p 1 -count=1 -race -timeout=3m -run 'TestCreateObject|TestBucketHandleTestSuite' ./internal/storage - passed on native Linux storage, including the existing bucket-adapter tests.
  3. Integration tests - Not run. The regression uses a local HTTP server; no real bucket or cloud credentials were used.

Any backward incompatible change? If so, please explain.

N/A. Successful uploads still close normally. A failed source read cancels only this call's upload and does not finalize partial data or cancel the caller's context.

Own a child context for each SDK writer and cancel it when CreateObject returns. Preserve the source error and caller context without closing or publishing a partial upload. Add a regression against the actual SDK writer.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a cancelable context for object uploads in CreateObject to ensure that abandoned uploads are properly canceled and cleaned up when an error occurs. Additionally, a new unit test TestCreateObjectCancelsUploadAfterSourceError has been added to verify this behavior. I have no feedback to provide as there are no review comments.

@singh4jitendra
singh4jitendra marked this pull request as ready for review November 17, 2026 05:30
@singh4jitendra
singh4jitendra requested a review from a team as a code owner November 17, 2026 05:30
@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @charith87, just following up on the failed-upload cleanup fix. Could you help approve the CI runs and take a look when you have a chance? Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @charith87, could you help approve the pending CI runs and review the upload cleanup fix when you have a chance? Happy to address any feedback. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @charith87, could you take a look at the upload cleanup fix when you get a chance? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant