-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(bigquery): add close() method to client for releasing open sockets #9894
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look great! A few suggestions.
A single common cleanup point at the end makes it much less likely to accidentally re-introduce an open socket leak.
@tswast Another thought - since the cleanup only happens if the user calls |
I'm working on a proposal to add |
Fixes #9790.
This PR fixes the client leaking open sockets by adding a
close()
method to the client for cleaning up after itself. It also fixes a similar leak in IPython magics - even if bqstorage client is used - when cell magic is run.How to test
Run both code samples from the issue description, i.e. the one using magics, and the other one using a regular BigQuery client. In both cases the number of open connections at the end should be the same as at the beginning, meaning that no connections (sockets) are leaked.
Misc.
The
magics._cell_magic()
needs refactoring, it's very long and several helper methods should be extracted from it. But that's out of this PR's scope.PR checklist