Repository navigation
Conversation
…d with a read handle When AsyncMultiRangeDownloader.open() is called without a read_handle and receives a BidiReadObjectRedirectedError containing both routing_token and read_handle, _on_open_error() previously adopted redirect.read_handle. Because the server omits BidiReadObjectResponse.metadata when a stream is opened with a read_handle, create_mrd() returned with persisted_size=None, is_finalized=False, full_obj_server_crc32c=None, and generation=None. Only adopt redirect.read_handle in _on_open_error() when self.read_handle is already set or routing_token is absent; otherwise retry with routing_token alone so the initial response includes object metadata and a fresh read_handle.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the _on_open_error method in AsyncMultiRangeDownloader to conditionally use the redirect's read handle. Specifically, the read handle is only adopted if the downloader already has a read handle or if the redirect lacks a routing token. This ensures that the subsequent retry attempt can retrieve the object metadata (such as persisted_size, is_finalized, and full_obj_server_crc32c) in its first response when a routing token is present. Additionally, comprehensive unit tests have been added to verify this behavior under different redirect scenarios. There are no review comments to address, and the changes look solid.
Contributor
Author
|
/gcbrun |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
AsyncMultiRangeDownloader.open()is called without aread_handleand receives aBidiReadObjectRedirectedErrorcontaining bothrouting_tokenandread_handle,_on_open_error()previously adopted the redirect'sread_handle. Because the server omitsBidiReadObjectResponse.metadatawhen a stream is opened with aread_handle,create_mrd()returned withpersisted_size=None,is_finalized=False,full_obj_server_crc32c=None, andgeneration=None._on_open_error()now retries withrouting_tokenalone unless the downloader already has aread_handleor the redirect has norouting_token.Fixes #19134
Changes
AsyncMultiRangeDownloader._on_open_error()(packages/google-cloud-storage/google/cloud/storage/asyncio/async_multi_range_downloader.py): only storeredirect.read_handlewhenself.read_handleis already set orrouting_tokenis absent; document the behavior.packages/google-cloud-storage/tests/unit/asyncio/test_async_multi_range_downloader.py:test_open_redirect_with_read_handle_keeps_object_metadata(initial open without handle, redirect with token + handle -> retries with token only and populatespersisted_size,is_finalized,full_obj_server_crc32c,generation, and server-returnedread_handle).test_open_redirect_adopts_read_handle(parametrized over caller-suppliedread_handleand handle-only redirect withoutrouting_token-> keeps adoptingredirect.read_handle).Testing
pytest tests/unit/asyncio/test_async_multi_range_downloader.py -k "test_open_redirect_"fails before the fix (read_handleadopted on retry,persisted_sizeisNone) and passes with it (3 passed).tests/unit/asyncio/suite: 408 passed, 18 skipped (only the 2 pre-existing local caplog-propagation failures intest_create_mrd_with_generation_numberandtest_unknown_read_id_is_droppedthat fail identically onmain).ruff check,ruff format --check, andflake8pass on both changed files.persisted_size=None, generation=Noneonmainandpersisted_size=36with the object's generation after this fix.