-
Notifications
You must be signed in to change notification settings - Fork 42
Description
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.