Skip to content

fix(storage): ensure bidi-gRPC stream is cleaned up on open failure and close - #18119

Draft
zhixiangli wants to merge 2 commits into
googleapis:mainfrom
zhixiangli:fix-bidi-stream-pending-task
Draft

fix(storage): ensure bidi-gRPC stream is cleaned up on open failure and close#18119
zhixiangli wants to merge 2 commits into
googleapis:mainfrom
zhixiangli:fix-bidi-stream-pending-task

Conversation

@zhixiangli

Copy link
Copy Markdown
Contributor
  • Ensure socket_like_rpc is closed if open() or the initial recv() fails or is cancelled in _AsyncReadObjectStream.open()
  • Add _close_socket_like_rpc helper to safely handle RPC closure
  • Only call requests_done() in close() if socket_like_rpc is active, and ensure stream state and RPC are closed even if requests_done() fails
  • Add unit tests for open failures/cancellations and close behavior on inactive or failing streams

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)

Fixes #<issue_number_goes_here> 🦕

…nd close

- Ensure socket_like_rpc is closed if open() or the initial recv() fails or is cancelled in _AsyncReadObjectStream.open()
- Add _close_socket_like_rpc helper to safely handle RPC closure
- Only call requests_done() in close() if socket_like_rpc is active, and ensure stream state and RPC are closed even if requests_done() fails
- Add unit tests for open failures/cancellations and close behavior on inactive or failing streams

@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 introduces robust exception handling and resource cleanup in _AsyncReadObjectStream during stream initialization and closure. Specifically, it wraps the bidi-gRPC stream opening and receiving logic in a try-except block to ensure the stream is closed if an error or cancellation occurs, and updates the close method to safely close the RPC connection even if signaling requests are done fails. Corresponding unit tests have been added to verify these error handling and cleanup paths. Feedback on the changes suggests consolidating the duplicate exception handling blocks for asyncio.CancelledError and Exception in the open method into a single block to reduce redundancy.

…nc_read_object_stream.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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