File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ def __init__(
105105 self .recv_task = None
106106
107107 self .is_started = asyncio .Event ()
108+ self .restart_event = asyncio .Event ()
108109
109110 async def start (self ):
110111 while True :
@@ -199,8 +200,10 @@ async def stop(self):
199200 log .info ("Session stopped" )
200201
201202 async def restart (self ):
203+ self .restart_event .set ()
202204 await self .stop ()
203205 await self .start ()
206+ self .restart_event .clear ()
204207
205208 async def handle_packet (self , packet ):
206209 try :
@@ -440,6 +443,16 @@ async def invoke(
440443 query_name , str (e ) or repr (e )
441444 )
442445
446+ # restart was never being called after Exception block
447+ if not self .restart_event .is_set ():
448+ self .loop .create_task (self .restart ())
449+ else :
450+ # multiple Exceptions can be raised in a row, so we need to wait for the restart to finish
451+ try :
452+ await asyncio .wait_for (self .restart_event .wait (), self .WAIT_TIMEOUT )
453+ except asyncio .TimeoutError :
454+ pass
455+
443456 await asyncio .sleep (0.5 )
444457
445458 return await self .invoke (query , retries - 1 , timeout )
You can’t perform that action at this time.
0 commit comments