diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index 3b3ca51a1c..96eba7c359 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -280,10 +280,13 @@ class Database(DatabaseInterface): res = [] for db_name, in cursor: try: - with connect(**self._connection_params(db_name) - ) as conn: - if self._test(conn, hostname=hostname): - res.append(db_name) + conn = connect(**self._connection_params(db_name)) + try: + with conn: + if self._test(conn, hostname=hostname): + res.append(db_name) + finally: + conn.close() except Exception: logger.debug( 'Test failed for "%s"', db_name, exc_info=True)