Skip to content

Commit

Permalink
Merge branch 'main' into refactor/allow-multiple-handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored Apr 10, 2024
2 parents 6aafc83 + 4a1f70b commit 1bf0702
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion silverback/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ async def run(self):
if len(tasks) == 0:
raise Halt("No tasks to execute")

await asyncio.gather(*tasks)
try:
await asyncio.gather(*tasks)
except Exception as e:
logger.error(f"Fatal error detected, shutting down: '{e}'")

# Execute Silverback shutdown task before shutting down the broker
for shutdown_task in self.app.tasks[TaskType.SHUTDOWN]:
Expand Down
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 1bf0702

Please sign in to comment.