@@ -833,7 +833,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
833833 pass
834834 if self .ws is not None :
835835 self ._exit_task = asyncio .create_task (self ._exit_with_timer ())
836- self ._attempts = 0
836+ self ._attempts = 0
837837
838838 async def _exit_with_timer (self ):
839839 """
@@ -891,12 +891,22 @@ async def _start_receiving(self, ws: ClientConnection) -> Exception:
891891 logger .debug ("Starting receiving task" )
892892 try :
893893 while True :
894- recd = await self ._wait_with_activity_timeout (
895- ws .recv (decode = False ), self .retry_timeout
896- )
897- await self ._reset_activity_timer ()
898- self ._attempts = 0
899- await self ._recv (recd )
894+ try :
895+ recd = await self ._wait_with_activity_timeout (
896+ ws .recv (decode = False ), self .retry_timeout
897+ )
898+ await self ._reset_activity_timer ()
899+ self ._attempts = 0
900+ await self ._recv (recd )
901+ except TimeoutError :
902+ if (
903+ self ._waiting_for_response <= 0
904+ or self ._sending .qsize () == 0
905+ or len (self ._inflight ) == 0
906+ or len (self ._received_subscriptions ) == 0
907+ ):
908+ # if there's nothing in a queue, we really have no reason to have this, so we continue to wait
909+ continue
900910 except websockets .exceptions .ConnectionClosedOK as e :
901911 logger .debug ("ConnectionClosedOK" )
902912 return e
@@ -939,7 +949,14 @@ async def _start_sending(self, ws) -> Exception:
939949 if not isinstance (
940950 e , (asyncio .TimeoutError , TimeoutError , ConnectionClosed )
941951 ):
942- logger .exception ("Websocket sending exception" , exc_info = e )
952+ logger .exception (
953+ f"Websocket sending exception; "
954+ f"sending: { self ._sending .qsize ()} ; "
955+ f"waiting_for_response: { self ._waiting_for_response } ; "
956+ f"inflight: { len (self ._inflight )} ; "
957+ f"subscriptions: { len (self ._received_subscriptions )} ;" ,
958+ exc_info = e ,
959+ )
943960 if to_send is not None :
944961 to_send_ = json .loads (to_send )
945962 self ._received [to_send_ ["id" ]].set_exception (e )
0 commit comments