File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 99
1010
1111class ARQStream :
12+ _active_tasks = set ()
13+
1214 def __init__ (
1315 self ,
1416 stream_id ,
@@ -53,6 +55,8 @@ def __init__(
5355 try :
5456 loop = asyncio .get_running_loop ()
5557 self .io_task = loop .create_task (self ._io_loop ())
58+ ARQStream ._active_tasks .add (self .io_task )
59+ self .io_task .add_done_callback (ARQStream ._active_tasks .discard )
5660 except RuntimeError :
5761 self .io_task = None
5862
@@ -93,9 +97,15 @@ async def _io_loop(self):
9397 self .window_not_full .clear ()
9498
9599 await self .enqueue_tx (3 , self .stream_id , sn , raw_data )
100+ except asyncio .CancelledError :
101+ pass
102+ except Exception as e :
103+ if self .logger :
104+ self .logger .debug (f"Stream { self .stream_id } IO loop error: { e } " )
96105 finally :
97106 if not self .closed :
98- await self .close (reason = "IO Loop Exit" )
107+ loop = asyncio .get_running_loop ()
108+ loop .create_task (self .close (reason = "IO Loop Exit" ))
99109
100110 async def receive_data (self , sn , data ):
101111 if self .closed :
Original file line number Diff line number Diff line change @@ -522,9 +522,11 @@ async def handle_dns_requests(self) -> None:
522522 continue
523523
524524 self .logger .error (f"Socket error: { e } . Exiting DNS request handler." )
525+ await asyncio .sleep (0.1 )
525526 continue
526527 except Exception as e :
527528 self .logger .exception (f"Unexpected error receiving DNS request: { e } " )
529+ await asyncio .sleep (0.1 )
528530 continue
529531 try :
530532 task = self .loop .create_task (self ._bounded_handle_request (data , addr ))
You can’t perform that action at this time.
0 commit comments