Skip to content

fix(storage): Reset write offset on gRPC BidiWriteObject resumable uploads#16083

Open
kalragauri wants to merge 2 commits intogoogleapis:mainfrom
kalragauri:feature/append-object
Open

fix(storage): Reset write offset on gRPC BidiWriteObject resumable uploads#16083
kalragauri wants to merge 2 commits intogoogleapis:mainfrom
kalragauri:feature/append-object

Conversation

@kalragauri
Copy link
Copy Markdown
Contributor

When a stream breaks, the connection enters a resume state. A key step in OnResume is to create a new underlying connection. This new connection is initialized to start writing data from the persisted size reported by the GCS backend.

The existing logic did not work as expected in some cases because it used relative decrements that became invalid after buffer truncation. This could happen if the size of payload persisted by the server did not match the size sent by the client.

This change introduces an is_resume flag to the OnQuery method. When OnQuery is called as part of the Resume() flow (i.e., after a new underlying connection is established), write_offset_ is now explicitly set to 0. This ensures that the WriteLoop correctly starts sending from the beginning of the truncated resend_buffer_ on the resumed stream.

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Apr 22, 2026
Copy link
Copy Markdown

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

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 modifies the OnQuery method in both AsyncWriterConnectionBuffered and AsyncWriterConnectionResumed to include an is_resume flag, ensuring that write_offset_ is correctly reset to zero upon a resume. Corresponding unit tests have been added to verify this logic. The review feedback highlights a potential integer underflow risk when updating write_offset_ if the server's reported persisted size exceeds the client's current write position, suggesting a defensive check to reset the offset to zero in such scenarios.

Comment thread google/cloud/storage/internal/async/writer_connection_buffered.cc
Comment thread google/cloud/storage/internal/async/writer_connection_resumed.cc
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 98.57143% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.71%. Comparing base (1b9b3c1) to head (244a1e1).

Files with missing lines Patch % Lines
.../internal/async/writer_connection_buffered_test.cc 97.61% 1 Missing ⚠️
...torage/internal/async/writer_connection_resumed.cc 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16083    +/-   ##
========================================
  Coverage   92.70%   92.71%            
========================================
  Files        2351     2351            
  Lines      217954   218088   +134     
========================================
+ Hits       202047   202190   +143     
+ Misses      15907    15898     -9     

☔ View full report in Codecov by Sentry.
📢 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 marked this pull request as ready for review April 22, 2026 07:29
@kalragauri kalragauri requested review from a team as code owners April 22, 2026 07:29
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