diff --git a/session_db/pg_session_store.py b/session_db/pg_session_store.py index 3feae5f2b5c..e5974232de5 100644 --- a/session_db/pg_session_store.py +++ b/session_db/pg_session_store.py @@ -23,7 +23,7 @@ def wrapper(self, *args, **kwargs): tries += 1 try: return func(self, *args, **kwargs) - except psycopg2.InterfaceError as e: + except (psycopg2.InterfaceError, psycopg2.OperationalError) as e: _logger.info("Session in DB connection Retry %s/5" % tries) if tries > 4: raise e @@ -49,6 +49,13 @@ def __del__(self): def _open_connection(self): cnx = odoo.sql_db.db_connect(self._uri, allow_uri=True) + try: + # return cursor to the pool + if self._cr is not None: + self._cr.close() + self._cr = None + except Exception: # pylint: disable=except-pass + pass self._cr = cnx.cursor() self._cr._cnx.autocommit = True