Skip to content

Commit

Permalink
fix: catch more shutdown issues to resolve shutdown without dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Apr 8, 2024
1 parent 2b99d60 commit aeec475
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion silverback/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import AsyncGenerator, Dict, List, Optional

from ape.logging import logger
from websockets import ConnectionClosedError
from websockets import client as ws_client


Expand Down Expand Up @@ -145,6 +146,12 @@ async def __aexit__(self, exc_type, exc, tb):
# Try to gracefully unsubscribe to all events
await asyncio.gather(*(self.unsubscribe(sub_id) for sub_id in self._subscriptions))

except ConnectionClosedError:
pass # Websocket already closed (ctrl+C and patiently waiting)

finally:
# Disconnect and release websocket
await self.connection.close()
try:
await self.connection.close()
except RuntimeError:
pass # No running event loop to disconnect from (multiple ctrl+C presses)

0 comments on commit aeec475

Please sign in to comment.