Skip to content

fix(storage): guard against overlapping stream requests in AsyncWriterConnectionBuffered - #16364

Merged
kalragauri merged 2 commits into
googleapis:mainfrom
kalragauri:feat/flush-uaf
Aug 21, 2026
Merged

fix(storage): guard against overlapping stream requests in AsyncWriterConnectionBuffered#16364
kalragauri merged 2 commits into
googleapis:mainfrom
kalragauri:feat/flush-uaf

Conversation

@kalragauri

Copy link
Copy Markdown
Contributor

In writer_connection_buffered.cc, WriteLoop previously computed its active state using:

writing_ = write_offset_ < resend_buffer_.size();

When an explicit Flush() was called with an empty/0-byte payload, resend_buffer_ had no unsent bytes, causing writing_ to evaluate to false. While FlushStep() was asynchronously executing on the gRPC stream, a subsequent operation (such as Finalize()) observed writing_ == false, bypassing the concurrency guard and initiating a concurrent gRPC operation on the same stream. This stream collision corrupted the gRPC state machine, causing pending promises to stall until timeout and resulting in premature teardown.

In this PR, WriteLoop has been updated to maintain writing_ = true across all dispatched asynchronous steps (WriteStep, FinalizeStep, CloseStep, FlushStep), clearing writing_ = false only when no operations are pending:

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Aug 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 the WriteLoop state machine in AsyncWriterConnectionBufferedState to manage the writing_ flag within individual execution branches, ensuring that the asynchronous pipeline is correctly marked as idle only when no further operations are pending. It also adds unit tests to verify that Finalize and Write operations are correctly queued and not executed concurrently while a Flush is in-flight. Feedback suggests simplifying WriteLoop by setting writing_ = true at the start of the function and only resetting it to false at the end if no asynchronous step is dispatched, which reduces duplicated code and aligns with the repository style guide.

Comment thread google/cloud/storage/internal/async/writer_connection_buffered.cc
@kalragauri
kalragauri marked this pull request as ready for review August 21, 2026 08:48
@kalragauri
kalragauri requested review from a team as code owners August 21, 2026 08:48
@kalragauri
kalragauri requested a review from v-pratap August 21, 2026 08:48
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.26%. Comparing base (03e43d3) to head (6e0db8f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16364      +/-   ##
==========================================
- Coverage   92.26%   92.26%   -0.01%     
==========================================
  Files        2237     2237              
  Lines      210434   210497      +63     
==========================================
+ Hits       194166   194207      +41     
- Misses      16268    16290      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalragauri
kalragauri merged commit 0ea426f into googleapis:main Aug 21, 2026
63 checks passed
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.

2 participants