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

contextmanager doesn't close connection on exit #125

Open
ErwinJunge opened this issue Dec 24, 2021 · 0 comments
Open

contextmanager doesn't close connection on exit #125

ErwinJunge opened this issue Dec 24, 2021 · 0 comments

Comments

@ErwinJunge
Copy link

When using Connection as a contextmanager, it doesn't close the connection when the context manager exits (https://github.com/chtd/psycopg2cffi/blob/master/psycopg2cffi/_impl/connection.py#L191). It only happens when it gets garbage collected (https://github.com/chtd/psycopg2cffi/blob/master/psycopg2cffi/_impl/connection.py#L184).

This lead to a bunch of dangling connections for me when running a test suite in pypy where I initialized some stuff in a fixture at the start of each test. Apparently pypy doesn't garbage collect quite as aggresively and I managed to run out of available connections in postgres.

In my opinion it would make a lot of sense to end __exit__ with self._close(), since you're not supposed to use the object after the contextmanager exits anyways.

I'd be happy to submit a PR if you agree.

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

No branches or pull requests

1 participant