session_db: reconnect if needed
If the connection to the database fails when retrying a session operation, we end up with no cursore, which makes subsequent session operations fail. We fix this by ensuring we have cursor before any operations.pull/2597/head
parent
1b5e684023
commit
13c570d639
|
@ -45,6 +45,7 @@ def with_cursor(func):
|
||||||
while True:
|
while True:
|
||||||
tries += 1
|
tries += 1
|
||||||
try:
|
try:
|
||||||
|
self._ensure_connection()
|
||||||
return func(self, *args, **kwargs)
|
return func(self, *args, **kwargs)
|
||||||
except (psycopg2.InterfaceError, psycopg2.OperationalError) as e:
|
except (psycopg2.InterfaceError, psycopg2.OperationalError) as e:
|
||||||
_logger.info("Session in DB connection Retry %s/5" % tries)
|
_logger.info("Session in DB connection Retry %s/5" % tries)
|
||||||
|
@ -67,6 +68,11 @@ class PGSessionStore(sessions.SessionStore):
|
||||||
if self._cr is not None:
|
if self._cr is not None:
|
||||||
self._cr.close()
|
self._cr.close()
|
||||||
|
|
||||||
|
@with_lock
|
||||||
|
def _ensure_connection(self):
|
||||||
|
if self._cr is None:
|
||||||
|
self._open_connection()
|
||||||
|
|
||||||
@with_lock
|
@with_lock
|
||||||
def _open_connection(self):
|
def _open_connection(self):
|
||||||
# return cursor to the pool
|
# return cursor to the pool
|
||||||
|
|
Loading…
Reference in New Issue