changeset ae0476e33d82 in trytond:6.2 details: https://hg.tryton.org/trytond?cmd=changeset&node=ae0476e33d82 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 7073f9719d8a -r ae0476e33d82 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 @@ -346,15 +346,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 @@ -380,7 +383,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]