Repository navigation
fix(storage): close the write stream when opening it fails - #19324
Open
Yonghui-Lee wants to merge 1 commit into
Open
Yonghui-Lee wants to merge 1 commit into
Yonghui-Lee wants to merge 1 commit into
Conversation
_AsyncWriteObjectStream.open did not close its AsyncBidiRpc when open() or the first recv() raised. On Rapid buckets every open first gets Aborted (zonal redirect) and the writer retries with a new stream, so each write left one pending gRPC request task behind. A failed create-only open (generation=0) left two. Close the RPC on failure, like the read stream already does, and re-raise the original error.
Contributor
There was a problem hiding this comment.
Code Review
This pull request ensures that the gRPC bidi-stream is properly closed if an error or cancellation occurs during the open() call in _AsyncWriteObjectStream, preventing request task leaks. It introduces a helper method _close_socket_like_rpc to handle stream closure safely and adds comprehensive unit tests to verify this behavior under various failure scenarios. No review comments were provided, and the implementation looks correct.
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
_AsyncWriteObjectStream.opendoesn't close itsAsyncBidiRpcwhenopen()or the firstrecv()raises. The read stream already does this through_close_socket_like_rpc. The appendable writer's retry only closes the old stream whenis_stream_openis true, and it's false here, so nobody closes it.On Rapid buckets every writer open first gets
Aborted(the zonal redirect) and then retries with the routing token. So each Rapid write leaves one pending gRPC_consume_request_iteratortask behind. A failed create-only open (generation=0on an existing object) leaves two. At interpreter exit they show up asTask was destroyed but it is pending!warnings.Changes
socket_like_rpc.open()and the firstrecv()in_AsyncWriteObjectStream.open. On any exception, includingasyncio.CancelledError, close the RPC and re-raise the original error._AsyncWriteObjectStream._close_socket_like_rpc, which closes the RPC and logs close errors at debug level so they don't hide the original error.is_stream_openstays false after a failed open, as before.open()andrecv()(Aborted,FailedPrecondition,CancelledError) and for a close that itself fails.Testing
tests/unit/asyncio/test_async_write_object_stream.pyandtest_async_appendable_object_writer.pypass. The 7 new test cases fail without the fix.Aborted, 3FailedPrecondition).