From 99135bf9db95140162079a353c6ea18bcd64f7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Sep 2020 23:02:14 +0200 Subject: [PATCH] Close connection after testing the database issue9629 review302191002 --- trytond/backend/postgresql/database.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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)