Skip to content

fix(storage): keep AsyncMultiRangeDownloader open after DataCorruption - #19170

Draft
zhixiangli wants to merge 1 commit into
googleapis:mainfrom
zhixiangli:storage-mrd-open-after-corruption
Draft

zhixiangli wants to merge 1 commit into
googleapis:mainfrom
zhixiangli:storage-mrd-open-after-corruption

Conversation

@zhixiangli

Copy link
Copy Markdown
Contributor

Keep AsyncMultiRangeDownloader open when download_ranges() raises DataCorruption.

Previously, AsyncMultiRangeDownloader.download_ranges() caught DataCorruption and called await self.close(), closing the entire downloader (stream, multiplexer, and pool) on a single checksum or byte-count mismatch. Any subsequent or concurrent download_ranges() call on the same MRD instance then failed with ValueError: Underlying bidi-gRPC stream is not open.

Removing the except DataCorruption: self-close block (while preserving finally: strategy.discard_pending_checksums(initial_state)) scopes the failure to the affected download_ranges() call so callers can retry the range or close the downloader explicitly.

Changes

  • packages/google-cloud-storage/google/cloud/storage/asyncio/async_multi_range_downloader.py: remove the except DataCorruption: self.close() handler in download_ranges(), and update the :raises DataCorruption: docstring to document that the downloader remains open.
  • packages/google-cloud-storage/tests/unit/asyncio/test_async_multi_range_downloader.py: add test_download_ranges_stays_open_on_datacorruption and test_download_ranges_after_datacorruption_reuses_mrd.
  • packages/google-cloud-storage/tests/unit/asyncio/test_rapid_observability.py: update test_async_multi_range_downloader_data_corruption_marks_span_error to assert mrd.is_stream_open remains True (span assertions unchanged).

Testing

  • pytest tests/unit/asyncio -k 'not (test_create_mrd_with_generation_number or test_unknown_read_id_is_dropped)': 425 passed, 2 deselected (the 2 deselected order-dependent caplog tests are pre-existing failures on upstream/main).
  • ruff check on touched files: passed.
  • Verified against real RAPID GCS and a local grpc.aio BidiReadObject server injecting a bad crc32c prior to rebase: after DataCorruption, is_stream_open remains True and subsequent + concurrent sibling download_ranges() calls reuse the open stream and return exact bytes.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

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

Copy link
Copy Markdown
Contributor

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 AsyncMultiRangeDownloader in the Google Cloud Storage asyncio package to keep the downloader stream open when a DataCorruption exception is raised, allowing callers to retry the range or close the stream manually. The docstrings, existing unit tests, and observability tests have been updated to reflect this change, and a new test has been added to verify that the downloader can be successfully reused after a data corruption event. There are no review comments to address, and I have no additional feedback to provide.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant