Skip to content

Commit

Permalink
[FIX] queue_job: handle exceptions in Database constructor
Browse files Browse the repository at this point in the history
Without this we risk connection leaks in case of exceptions in the
constructor.
  • Loading branch information
sbidoul authored and qgroulard committed Jul 18, 2024
1 parent 1b3fd3a commit 6434263
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions queue_job/jobrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,14 @@ def __init__(self, db_name):
self.db_name = db_name
connection_info = _connection_info_for(db_name)
self.conn = psycopg2.connect(**connection_info)
self.conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
self.has_queue_job = self._has_queue_job()
if self.has_queue_job:
self._initialize()
try:
self.conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
self.has_queue_job = self._has_queue_job()
if self.has_queue_job:
self._initialize()
except BaseException:
self.close()
raise

def close(self):
# pylint: disable=except-pass
Expand Down

0 comments on commit 6434263

Please sign in to comment.