Skip to content
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

It's possible for a socket to be left open #100

Closed
kurtmckee opened this issue Apr 12, 2022 · 2 comments
Closed

It's possible for a socket to be left open #100

kurtmckee opened this issue Apr 12, 2022 · 2 comments

Comments

@kurtmckee
Copy link
Contributor

kurtmckee commented Apr 12, 2022

After configuring sqlalchemy-utils' unit tests to escalate warnings to errors, it was revealed that the root cause of a ResourceWarning was a socket that is opened in pg8000.core.CoreConnection.__init__() but is not closed when an error is detected:

pg8000/pg8000/core.py

Lines 341 to 342 in 121f754

if self.error is not None:
raise self.error

Python's garbage collector will eventually collect the socket object and throw a ResourceWarning. I have tested and found that calling self.close() immediately prior to raising self.error will resolve this problem.

This is related to kvesteri/sqlalchemy-utils#590.

@tlocke
Copy link
Owner

tlocke commented Apr 15, 2022

Thanks for this bug report and patch @kurtmckee. I've used your PR and done a new release (1.24.2). I hadn't thought about the fact that if there's an exception in a constructor, there's no handle on the object and so resources associated with it can't be freed.

@kurtmckee
Copy link
Contributor Author

You're welcome! Thanks for your work on pg8000!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants