Skip to content

Commit fb729d2

Browse files
committed
Ensures that we do not attempt to reconnect if there are open subscriptions.
1 parent 339fdd5 commit fb729d2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ async def _handler(self, ws: ClientConnection) -> Union[None, Exception]:
646646
self._attempts += 1
647647
is_retry = True
648648
if should_reconnect is True:
649+
if len(self._received_subscriptions) > 0:
650+
return SubstrateRequestException(
651+
f"Unable to reconnect because there are currently open subscriptions."
652+
)
649653
for original_id, payload in list(self._inflight.items()):
650654
self._received[original_id] = loop.create_future()
651655
to_send = json.loads(payload)
@@ -662,6 +666,11 @@ async def _handler(self, ws: ClientConnection) -> Union[None, Exception]:
662666
return e
663667
elif isinstance(e := send_task.result(), Exception):
664668
return e
669+
elif len(self._received_subscriptions) > 0:
670+
return SubstrateRequestException(
671+
f"Currently open subscriptions while disconnecting. "
672+
f"Ensure these are unsubscribed from before closing in the future."
673+
)
665674
return None
666675

667676
async def __aexit__(self, exc_type, exc_val, exc_tb):

0 commit comments

Comments
 (0)