Skip to content

fix(storage): complete active ranges when ObjectDescriptorImpl is cancelled - #16746

Open
kalragauri wants to merge 4 commits into
googleapis:mainfrom
kalragauri:fix/storage-descriptor-cancel-completes-ranges
Open

kalragauri wants to merge 4 commits into
googleapis:mainfrom
kalragauri:fix/storage-descriptor-cancel-completes-ranges

Conversation

@kalragauri

Copy link
Copy Markdown
Contributor

Destroying an ObjectDescriptor while any range read started from it has not finished leaves AsyncReader::Read() hanging forever. ~ObjectDescriptorImpl() calls ObjectDescriptorImpl::Cancel() to cancel the underlying streams and then destroys stream_manager_, without ever calling ReadRange::OnFinish(). Because stream callbacks hold weak pointers to the descriptor, nothing completes the orphaned ReadRange objects once the descriptor is gone. Any AsyncReader destroyed early on such a range also leaks its Discard background loop indefinitely because that loop keeps waiting on ReadRange::Read().

This change adds MultiStreamManager::TakeActiveRanges() to detach all active ranges across all streams under mu_, passes AsyncConnectionImpl's CompletionQueue into ObjectDescriptorImpl, and updates ObjectDescriptorImpl::Cancel() to complete every detached range with StatusCode::kCancelled after releasing mu_. Notifications are scheduled through CompletionQueue::MakeRelativeTimer(0ns) so pending read continuations and suspended coroutines run shortly after ~ObjectDescriptor() returns on a completion-queue thread rather than inline inside the destructor, falling back to the destroying thread only when the queue has already been shut down. The ObjectDescriptor class documentation now states this lifetime contract, and open read tracing spans now end with StatusCode::kCancelled instead of staying open forever. Calling ObjectDescriptorImpl::Read() after Cancel() on a live internal object is intentionally left unchanged because no public API exposes Cancel() on a live descriptor, and ObjectDescriptorReader::Cancel() for readers whose descriptor is still alive is left for a separate change.

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Dec 3, 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 updates ObjectDescriptor and its implementation to ensure that destroying a descriptor cancels any unfinished reads, scheduling cancellation notifications on the completion queue rather than running them inline. To support this, MultiStreamManager introduces TakeActiveRanges(), and ObjectDescriptorImpl now accepts and utilizes a CompletionQueue. The feedback highlights a style guide violation regarding the use of default argument values in constructors within internal namespaces, which should be removed.

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.23060% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.92%. Comparing base (79985ca) to head (d7f362a).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...le/cloud/storage/internal/async/connection_impl.cc 58.33% 10 Missing ⚠️
...rage/internal/async/object_descriptor_impl_test.cc 98.02% 6 Missing ⚠️
...loud/storage/internal/async/multi_stream_manager.h 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16746      +/-   ##
==========================================
+ Coverage   92.91%   92.92%   +0.01%     
==========================================
  Files        2282     2282              
  Lines      232266   232653     +387     
==========================================
+ Hits       215820   216204     +384     
- Misses      16446    16449       +3     

☔ 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 marked this pull request as ready for review December 3, 2026 11:17
@kalragauri
kalragauri requested review from a team as code owners December 3, 2026 11:17

This branch has not been deployed

No deployments
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