Skip to content

fix(storage): consume server responses before finishing stream in AsyncWriter Close/Finalize#16270

Open
kalragauri wants to merge 3 commits into
googleapis:mainfrom
kalragauri:feat/close-hangs
Open

fix(storage): consume server responses before finishing stream in AsyncWriter Close/Finalize#16270
kalragauri wants to merge 3 commits into
googleapis:mainfrom
kalragauri:feat/close-hangs

Conversation

@kalragauri

@kalragauri kalragauri commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This PR fixes an issue where calling AsyncWriter::Close() or Finalize() hangs indefinitely when the GCS service returns intermediate response messages before closing the stream.

Under the hood, Close() sends a kFlushAndClose request, which prompts GCS to respond. Previously, AsyncWriterConnectionImpl called Finish() on the underlying gRPC stream immediately after writing without consuming any remaining server responses. This unread data on the stream caused Finish() to block waiting for response consumption, leading to a deadlock.

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Jul 21, 2026

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

Copy link
Copy Markdown

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 refactors OnClose and OnFinalUpload in AsyncWriterConnectionImpl to use a recursive ConsumeLoop that reads and processes all intermediate server responses before finalizing the upload, preventing hangs when multiple responses are sent before EOF. Corresponding unit tests are updated and a new test is added to verify this behavior. The review feedback correctly identifies compilation errors in both refactored methods where the undefined variable self is referenced inside lambdas capturing [this], and provides code suggestions to resolve these issues by calling Finish() directly.

Comment thread google/cloud/storage/internal/async/writer_connection_impl.cc Outdated
Comment thread google/cloud/storage/internal/async/writer_connection_impl.cc Outdated
@kalragauri
kalragauri force-pushed the feat/close-hangs branch 4 times, most recently from 6d2b7b3 to cc63d2d Compare July 21, 2026 10:00
@kalragauri
kalragauri marked this pull request as ready for review July 21, 2026 10:22
@kalragauri
kalragauri requested review from a team as code owners July 21, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant