Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(storage): cancel ReadRange in ObjectDescriptorReader::Cancel() - #16758

Draft
ajayky-os wants to merge 1 commit into
googleapis:mainfrom
ajayky-os:fix/storage-object-descriptor-reader-cancel
Draft

ajayky-os wants to merge 1 commit into
googleapis:mainfrom
ajayky-os:fix/storage-object-descriptor-reader-cancel

Conversation

@ajayky-os

Copy link
Copy Markdown
Contributor

Summary

  • Implement ObjectDescriptorReader::Cancel() so cancelling or destroying an AsyncReader backed by an active ObjectDescriptor cleanly cancels its ReadRange.

Problem

ObjectDescriptorReader::Cancel() was previously an empty no-op:

  1. Destroying an AsyncReader while a Read() was pending caused ~AsyncReader()'s Discard loop to call ReadRange::Read() a second time, overwriting the parked wait_ promise and failing the caller's future with std::future_error: Broken promise.
  2. Destroying an AsyncReader early left ReadRange alive in the background Discard loop until stream completion and caused RangeForResume() to replay the cancelled range across stream reconnects.
  3. Calling Cancel() directly on ObjectDescriptorReader and draining Read() delivered the rest of the range followed by Status{} (OK).

Changes

  • google/cloud/storage/internal/async/object_descriptor_reader.cc: Call impl_->OnFinish(google::cloud::internal::CancelledError("range read cancelled", GCP_ERROR_INFO())) in ObjectDescriptorReader::Cancel().
    • Immediately satisfies any pending Read() with StatusCode::kCancelled.
    • Marks IsDone() == true so ObjectDescriptorImpl removes the range on cleanup and RangeForResume() returns std::nullopt.
    • Ignores subsequent OnRead() chunks while letting ~AsyncReader()'s Discard loop drain synchronously and release the ReadRange.
    • ObjectDescriptorReaderTracing inherits Cancel() directly without overriding it.
  • google/cloud/storage/internal/async/object_descriptor_reader_test.cc: Added 4 unit tests covering direct Cancel(), ~AsyncReader() with a pending Read(), ~AsyncReader() releasing ReadRange, and ignoring post-cancel chunks.

Testing

  • //google/cloud/storage:internal_async_object_descriptor_reader_test — PASSED (5/5)
  • //google/cloud/storage:async_reader_test — PASSED
  • //google/cloud/storage:internal_async_object_descriptor_impl_test — PASSED

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Dec 4, 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 implements the Cancel method in ObjectDescriptorReader to support cancelling range reads, returning a cancelled status. It also adds comprehensive unit tests to verify cancellation behavior, destructor behavior, and handling of subsequent chunks after cancellation. The review feedback points out two style guide violations where auto is used for string literals (kData0 and kData1) in the tests, and recommends using explicit types instead.

@ajayky-os
ajayky-os force-pushed the fix/storage-object-descriptor-reader-cancel branch from fba846d to 8121f07 Compare December 4, 2026 08:03
@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.95%. Comparing base (daf351d) to head (5490e48).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16758   +/-   ##
=======================================
  Coverage   92.95%   92.95%           
=======================================
  Files        2284     2284           
  Lines      234065   234118   +53     
=======================================
+ Hits       217566   217617   +51     
- Misses      16499    16501    +2     

☔ 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.

@ajayky-os
ajayky-os force-pushed the fix/storage-object-descriptor-reader-cancel branch from 8121f07 to dd33bbb Compare December 4, 2026 09:13
ObjectDescriptorReader::Cancel() was previously a no-op, so destroying an
AsyncReader while its parent ObjectDescriptor stays alive left the range active:
- A pending Read() ended with std::future_error: Broken promise when ~AsyncReader()
  started its background Discard loop and called ReadRange::Read() a second time.
- The background Discard loop kept reading and discarding chunks until EOF and
  retained the ReadRange indefinitely if no data arrived.
- RangeForResume() continued replaying the cancelled range across stream resumes.

Implement ObjectDescriptorReader::Cancel() by calling
impl_->OnFinish(CancelledError(...)), which immediately completes any pending
Read() with kCancelled, marks IsDone() true, returns std::nullopt from
RangeForResume(), ignores subsequent OnRead() chunks, and lets ~AsyncReader()'s
Discard loop terminate and release the ReadRange immediately. Because
ObjectDescriptorReaderTracing inherits from ObjectDescriptorReader without
overriding Cancel(), traced readers automatically inherit this fix.
@ajayky-os
ajayky-os force-pushed the fix/storage-object-descriptor-reader-cancel branch from dd33bbb to 5490e48 Compare December 4, 2026 10:05

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