FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(bigquery): add close() method to client for releasing open sockets by plamut · Pull Request #9894 · googleapis/google-cloud-python · GitHub

fix(bigquery): add close() method to client for releasing open sockets - #9894

Merged
tswast merged 5 commits into
googleapis:masterfrom
plamut:iss-9790
Nov 27, 2019
Merged

fix(bigquery): add close() method to client for releasing open sockets#9894
tswast merged 5 commits into
googleapis:masterfrom
plamut:iss-9790

Conversation

plamut commented Nov 26, 2019
edited
Loading

Copy link
Copy Markdown
Contributor

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)

plamut added the api: bigquery Issues related to the BigQuery API. label Nov 26, 2019
plamut requested review from a team and tswast November 26, 2019 23:22
googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 26, 2019

tswast 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Tests look great! A few suggestions.

Comment thread bigquery/setup.py Outdated
A single common cleanup point at the end makes it much less likely
to accidentally re-introduce an open socket leak.
Comment thread bigquery/noxfile.py
plamut requested a review from tswast November 27, 2019 13:36

plamut commented Nov 27, 2019

Copy link
Copy Markdown
Contributor Author

@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.

tswast commented Nov 27, 2019

Copy link
Copy Markdown
Contributor

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.

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

Labels

api: bigquery Issues related to the BigQuery API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQuery: resource leaks in client and %%bigquery magics

3 participants


Back | FazBrowse Home | New Git URL