GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@plamut plamut commented Nov 26, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
plamut added 3 commits November 26, 2019 21:38
@plamut
Add psutil as an extra test dependency
a4c271f
@plamut
Add close() method to Client
d27618c
@plamut
Fix open sockets leak in IPython magics
ae63a4f
@plamut plamut added the api: bigquery Issues related to the BigQuery API. label Nov 26, 2019
@plamut
plamut requested review from a team and tswast November 26, 2019 23:22
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 26, 2019
tswast
tswast reviewed Nov 27, 2019
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread bigquery/google/cloud/bigquery/magics.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/setup.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

plamut added 2 commits November 27, 2019 13:29
@plamut
Move psutil test dependency to noxfile
827a4cf
@plamut
Wrap entire cell magic into try-finally block
7dff06f
A single common cleanup point at the end makes it much less likely
to accidentally re-introduce an open socket leak.
plamut
plamut commented Nov 27, 2019
View reviewed changes
Comment thread bigquery/noxfile.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut
plamut requested a review from tswast November 27, 2019 13:36
@plamut

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tswast
tswast approved these changes Nov 27, 2019
View reviewed changes
@tswast

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast
tswast merged commit 9360057 into googleapis:master Nov 27, 2019
@plamut
plamut deleted the iss-9790 branch November 27, 2019 22:14
This was referenced Jan 29, 2020
chore(bigquery): bump copyright year to 2020, tweak docstring formatting (via synth) #10225
Merged
[CHANGE ME] Re-generated container to pick up changes in the API or client library generator. #10256
Closed
[CHANGE ME] Re-generated datastore to pick up changes in the API or client library generator. #10261
Closed
@busunkim96 busunkim96 mentioned this pull request Mar 24, 2020
fix: don't use threads for gRPC AuthMetadataPlugin, reverts #390 googleapis/google-auth-library-python#467
Merged
@tswast tswast mentioned this pull request Aug 18, 2020
Feature Request: allow clients to act as context manager and add close() method to cleanup resources googleapis/gapic-generator-python#575
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BigQuery: resource leaks in client and %%bigquery magics

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@plamut @tswast @googlebot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.