GeezerVison is showing github.com — fix(bigquery): add close() method to client for releasing open sockets by plamut · Pull Request #9894 · googleapis/google-cloud-python
Conversation
plamut
commented
Nov 26, 2019
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
- 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)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
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.
A single common cleanup point at the end makes it much less likely
to accidentally re-introduce an open socket leak.
Uh oh!
There was an error while loading. Please reload this page.
|
@tswast Another thought - since the cleanup only happens if the user calls .close(), we should probably update our code samples to include the client.close() line at the end. Otherwise I presume that many users will simply forget or not know about this.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I'm working on a proposal to add close() to all clients and make clients act as a context manager. Once this is done, we'll likely need to update our sample rubric to account for this.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jan 29, 2020
Reviewers
tswast
tswast approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
api: bigquery
Issues related to the BigQuery API.
cla: yes
This human has signed the Contributor License Agreement.
Milestone
No milestone
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.
|