mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 07:31:12 +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
1 changed files with 5 additions and 1 deletions
|
@ -4,6 +4,8 @@ import psycopg2
|
|||
import select
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from app.db import Session
|
||||
from app.log import LOG
|
||||
from app.models import SyncEvent
|
||||
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}")
|
||||
except Exception as 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):
|
||||
self.__connection = psycopg2.connect(self.__connection_string)
|
||||
|
@ -97,7 +100,8 @@ class DeadLetterEventSource(EventSource):
|
|||
)
|
||||
for event in events:
|
||||
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")
|
||||
sleep(_DEAD_LETTER_INTERVAL_SECONDS)
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in a new issue