diff --git a/session_db/pg_session_store.py b/session_db/pg_session_store.py index 849e431de..5dc02fe0d 100644 --- a/session_db/pg_session_store.py +++ b/session_db/pg_session_store.py @@ -45,6 +45,7 @@ def with_cursor(func): while True: tries += 1 try: + self._ensure_connection() return func(self, *args, **kwargs) except (psycopg2.InterfaceError, psycopg2.OperationalError) as e: _logger.info("Session in DB connection Retry %s/5" % tries) @@ -67,6 +68,11 @@ class PGSessionStore(sessions.SessionStore): if self._cr is not None: self._cr.close() + @with_lock + def _ensure_connection(self): + if self._cr is None: + self._open_connection() + @with_lock def _open_connection(self): # return cursor to the pool