@@ -575,7 +575,6 @@ async def loop_time() -> float:
575
575
async def _cancel (self ):
576
576
try :
577
577
self ._send_recv_task .cancel ()
578
- await self ._send_recv_task
579
578
await self .ws .close ()
580
579
except (
581
580
AttributeError ,
@@ -619,7 +618,7 @@ async def _handler(self, ws: ClientConnection) -> None:
619
618
for task in pending :
620
619
task .cancel ()
621
620
for task in done :
622
- if isinstance (task .result (), (asyncio .TimeoutError , ConnectionClosed )):
621
+ if isinstance (task .result (), (asyncio .TimeoutError , ConnectionClosed , TimeoutError )):
623
622
should_reconnect = True
624
623
if should_reconnect is True :
625
624
for original_id , payload in list (self ._inflight .items ()):
@@ -628,7 +627,7 @@ async def _handler(self, ws: ClientConnection) -> None:
628
627
await self ._sending .put (to_send )
629
628
logger .info ("Timeout occurred. Reconnecting." )
630
629
await self .connect (True )
631
- await self ._handler (ws = ws )
630
+ await self ._handler (ws = self . ws )
632
631
elif isinstance (e := recv_task .result (), Exception ):
633
632
return e
634
633
elif isinstance (e := send_task .result (), Exception ):
@@ -691,13 +690,16 @@ async def _start_receiving(self, ws: ClientConnection) -> Exception:
691
690
)
692
691
await self ._recv (recd )
693
692
except Exception as e :
694
- logger .exception ("Start receiving exception" , exc_info = e )
695
693
if isinstance (e , ssl .SSLError ):
696
694
e = ConnectionClosed
697
- for fut in self ._received .values ():
698
- if not fut .done ():
699
- fut .set_exception (e )
700
- fut .cancel ()
695
+ if not isinstance (e , (asyncio .TimeoutError , TimeoutError , ConnectionClosed )):
696
+ logger .exception ("Websocket receiving exception" , exc_info = e )
697
+ for fut in self ._received .values ():
698
+ if not fut .done ():
699
+ fut .set_exception (e )
700
+ fut .cancel ()
701
+ else :
702
+ logger .warning ("Timeout occurred. Reconnecting." )
701
703
return e
702
704
703
705
async def _start_sending (self , ws ) -> Exception :
@@ -713,14 +715,19 @@ async def _start_sending(self, ws) -> Exception:
713
715
raw_websocket_logger .debug (f"WEBSOCKET_SEND> { to_send } " )
714
716
await ws .send (to_send )
715
717
except Exception as e :
716
- logger .exception ("Start sending exception" , exc_info = e )
717
- if to_send is not None :
718
- self ._received [to_send ["id" ]].set_exception (e )
719
- self ._received [to_send ["id" ]].cancel ()
718
+ if isinstance (e , ssl .SSLError ):
719
+ e = ConnectionClosed
720
+ if not isinstance (e , (asyncio .TimeoutError , TimeoutError , ConnectionClosed )):
721
+ logger .exception ("Websocket sending exception" , exc_info = e )
722
+ if to_send is not None :
723
+ self ._received [to_send ["id" ]].set_exception (e )
724
+ self ._received [to_send ["id" ]].cancel ()
725
+ else :
726
+ for i in self ._received .keys ():
727
+ self ._received [i ].set_exception (e )
728
+ self ._received [i ].cancel ()
720
729
else :
721
- for i in self ._received .keys ():
722
- self ._received [i ].set_exception (e )
723
- self ._received [i ].cancel ()
730
+ logger .warning ("Timeout occurred. Reconnecting." )
724
731
return e
725
732
726
733
async def send (self , payload : dict ) -> str :
0 commit comments