diff --git a/broadcaster/__init__.py b/broadcaster/__init__.py index 9ed6a64..fc13f68 100644 --- a/broadcaster/__init__.py +++ b/broadcaster/__init__.py @@ -1,4 +1,4 @@ from ._base import Broadcast, Event -__version__ = "0.2.4" +__version__ = "0.2.5" __all__ = ["Broadcast", "Event"] diff --git a/broadcaster/_backends/postgres.py b/broadcaster/_backends/postgres.py index 0748ec9..fbc8f84 100644 --- a/broadcaster/_backends/postgres.py +++ b/broadcaster/_backends/postgres.py @@ -31,7 +31,12 @@ async def connect(self) -> None: self._conn.add_termination_listener(self._termination_listener) async def disconnect(self) -> None: - self._conn.remove_termination_listener(self._termination_listener) + try: + self._conn.remove_termination_listener(self._termination_listener) + except Exception: + # Best effort, would fail if conn already closed (thus released) + pass + await (await self._get_pool()).release(self._conn) self._conn = None @@ -39,7 +44,11 @@ async def subscribe(self, channel: str) -> None: await self._conn.add_listener(channel, self._listener) async def unsubscribe(self, channel: str) -> None: - await self._conn.remove_listener(channel, self._listener) + try: + await self._conn.remove_listener(channel, self._listener) + except Exception: + # Best effort, would fail if conn already closed (thus released) + pass async def publish(self, channel: str, message: str) -> None: await self._conn.execute("SELECT pg_notify($1, $2);", channel, message)