Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions async_substrate_interface/async_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
pass
if self.ws is not None:
self._exit_task = asyncio.create_task(self._exit_with_timer())
self._attempts = 0
self._attempts = 0

async def _exit_with_timer(self):
"""
Expand Down Expand Up @@ -891,12 +891,22 @@ async def _start_receiving(self, ws: ClientConnection) -> Exception:
logger.debug("Starting receiving task")
try:
while True:
recd = await self._wait_with_activity_timeout(
ws.recv(decode=False), self.retry_timeout
)
await self._reset_activity_timer()
self._attempts = 0
await self._recv(recd)
try:
recd = await self._wait_with_activity_timeout(
ws.recv(decode=False), self.retry_timeout
)
await self._reset_activity_timer()
self._attempts = 0
await self._recv(recd)
except TimeoutError:
if (
self._waiting_for_response <= 0
or self._sending.qsize() == 0
or len(self._inflight) == 0
or len(self._received_subscriptions) == 0
):
# if there's nothing in a queue, we really have no reason to have this, so we continue to wait
continue
except websockets.exceptions.ConnectionClosedOK as e:
logger.debug("ConnectionClosedOK")
return e
Expand Down Expand Up @@ -939,7 +949,14 @@ async def _start_sending(self, ws) -> Exception:
if not isinstance(
e, (asyncio.TimeoutError, TimeoutError, ConnectionClosed)
):
logger.exception("Websocket sending exception", exc_info=e)
logger.exception(
f"Websocket sending exception; "
f"sending: {self._sending.qsize()}; "
f"waiting_for_response: {self._waiting_for_response}; "
f"inflight: {len(self._inflight)}; "
f"subscriptions: {len(self._received_subscriptions)};",
exc_info=e,
)
if to_send is not None:
to_send_ = json.loads(to_send)
self._received[to_send_["id"]].set_exception(e)
Expand Down
Loading