mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 21:27:10 +01:00
Close sessions between loops to make sure we leave no lock (#2162)
* Close sessions between loops to make sure we leave no lock * Close at the end * Close before sleeps * Use python generic empty list in case the events is an iterator
This commit is contained in:
parent
666bf86441
commit
8262390bf0
@ -4,6 +4,8 @@ import psycopg2
|
|||||||
import select
|
import select
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
from app.db import Session
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import SyncEvent
|
from app.models import SyncEvent
|
||||||
from app.events.event_dispatcher import NOTIFICATION_CHANNEL
|
from app.events.event_dispatcher import NOTIFICATION_CHANNEL
|
||||||
@ -66,6 +68,7 @@ class PostgresEventSource(EventSource):
|
|||||||
LOG.info(f"Could not find event with id={notify.payload}")
|
LOG.info(f"Could not find event with id={notify.payload}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warn(f"Error getting event: {e}")
|
LOG.warn(f"Error getting event: {e}")
|
||||||
|
Session.close() # Ensure we get a new connection and we don't leave a dangling tx
|
||||||
|
|
||||||
def __connect(self):
|
def __connect(self):
|
||||||
self.__connection = psycopg2.connect(self.__connection_string)
|
self.__connection = psycopg2.connect(self.__connection_string)
|
||||||
@ -97,7 +100,8 @@ class DeadLetterEventSource(EventSource):
|
|||||||
)
|
)
|
||||||
for event in events:
|
for event in events:
|
||||||
on_event(event)
|
on_event(event)
|
||||||
else:
|
Session.close() # Ensure that we have a new connection and we don't have a dangling tx with a lock
|
||||||
|
if not events:
|
||||||
LOG.debug("No dead letter events")
|
LOG.debug("No dead letter events")
|
||||||
sleep(_DEAD_LETTER_INTERVAL_SECONDS)
|
sleep(_DEAD_LETTER_INTERVAL_SECONDS)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user