diff --git a/lib/repositories/repo.py b/lib/repositories/repo.py index 12b63bb..38fa949 100644 --- a/lib/repositories/repo.py +++ b/lib/repositories/repo.py @@ -20,6 +20,7 @@ def __new__(cls, *args, **kwargs): return cls._instances[cls] def __init__(self, collection_name: str): + self._entered = False if not getattr(self, '_initialized', False): self._collection_name = collection_name self._initialized_event = asyncio.Event() @@ -45,7 +46,8 @@ async def _async_init(self): self._initialized_event.set() async def __aenter__(self): - await self._initialized_event.wait() + if not self._entered: + await self._initialized_event.wait() return self async def __aexit__(self, exc_type, exc_value, traceback): @@ -63,7 +65,7 @@ def _initialize_connection(self): server_api=ServerApi("1"), maxIdleTimeMS=5000, connectTimeoutMS=5000, - serverSelectionTimeoutMS=15000, + serverSelectionTimeoutMS=30000, ) self._collection = self._client.rocketpy[self._collection_name] logger.info("MongoDB client initialized for %s", self.__class__)