Uh oh!
There was an error while loading. Please reload this page.
fix(bigquery): dbapi socket leak - #17921
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Connection.close() method to explicitly close the underlying gRPC channel of the BigQuery Storage client's transport, preventing potential socket leaks. It also refactors unit tests to mock the public transport property instead of the private _transport attribute. The review feedback suggests using mock.patch.object with self.addCleanup to prevent test pollution when mocking the transport property, and using getattr instead of hasattr to safely check for _grpc_channel and avoid potential AttributeErrors if the channel is None.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
🤖 I have created a release *beep* *boop* --- ## [3.42.3](google-cloud-bigquery-v3.42.2...google-cloud-bigquery-v3.42.3) (2026-07-30) ### Bug Fixes * **bigquery:** dbapi socket leak ([#17921](#17921)) ([d328e3b](d328e3b)) * bump grpcio to 1.59.0; require Python 3.10+ ([#17351](#17351)) ([a53487a](a53487a)) * require Protobuf 6.33.5+ ([#17743](#17743)) ([d267342](d267342)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Problem
The system test
test_dbapi_connection_does_not_leak_socketsfails intermittently because network connections remain in theESTABLISHEDstate even afterconnection.close()is called. This is likely due to the underlying gRPC (remote procedure call) transport not being immediately closed, or delays in Garbage Collection (cleaning up unused memory).Solution
This Pull Request updates
Connection.close()to explicitly close the underlying gRPC channel (transport._grpc_channel) if it exists on the BigQuery Storage client. This ensures that the connection is closed immediately and resources are released deterministically.Notes to Reviewers
ESTABLISHEDsockets.Sample debug info from traceback: