From fb729d29439d791fef13c1e5e9556b4882a71109 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Wed, 8 Oct 2025 20:28:58 +0200 Subject: [PATCH] Ensures that we do not attempt to reconnect if there are open subscriptions. --- async_substrate_interface/async_substrate.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index 99ce28b..a93af0c 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -646,6 +646,10 @@ async def _handler(self, ws: ClientConnection) -> Union[None, Exception]: self._attempts += 1 is_retry = True if should_reconnect is True: + if len(self._received_subscriptions) > 0: + return SubstrateRequestException( + f"Unable to reconnect because there are currently open subscriptions." + ) for original_id, payload in list(self._inflight.items()): self._received[original_id] = loop.create_future() to_send = json.loads(payload) @@ -662,6 +666,11 @@ async def _handler(self, ws: ClientConnection) -> Union[None, Exception]: return e elif isinstance(e := send_task.result(), Exception): return e + elif len(self._received_subscriptions) > 0: + return SubstrateRequestException( + f"Currently open subscriptions while disconnecting. " + f"Ensure these are unsubscribed from before closing in the future." + ) return None async def __aexit__(self, exc_type, exc_val, exc_tb):