changeset ffac357d4312 in trytond:6.0 details: https://hg.tryton.org/trytond?cmd=changeset&node=ffac357d4312 description: Catch get_connection errors in Cache listener
issue11563 review411271003 (grafted from 7123014d260c278bd36a25d9c4a7543db553733c) diffstat: trytond/cache.py | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diffs (40 lines): diff -r cb78ca4f66ed -r ffac357d4312 trytond/cache.py --- a/trytond/cache.py Thu Sep 15 21:49:12 2022 +0200 +++ b/trytond/cache.py Sat Sep 17 19:00:48 2022 +0200 @@ -347,15 +347,18 @@ @classmethod def _listen(cls, dbname): - database = backend.Database(dbname) - if not database.has_channel(): - raise NotImplementedError + current_thread = threading.current_thread() + pid = os.getpid() + conn = None + try: + database = backend.Database(dbname) + if not database.has_channel(): + raise NotImplementedError - logger.info("listening on channel '%s' of '%s'", cls._channel, dbname) - conn = database.get_connection(autocommit=True) - pid = os.getpid() - current_thread = threading.current_thread() - try: + logger.info( + "listening on channel '%s' of '%s'", cls._channel, dbname) + conn = database.get_connection(autocommit=True) + cursor = conn.cursor() cursor.execute('LISTEN "%s"' % cls._channel) current_thread.listening = True @@ -381,7 +384,8 @@ "cache listener on '%s' crashed", dbname, exc_info=True) raise finally: - database.put_connection(conn) + if conn: + database.put_connection(conn) with cls._listener_lock[pid]: if cls._listener.get((pid, dbname)) == current_thread: del cls._listener[pid, dbname]