File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -271,7 +271,29 @@ def main():
271271 log .info ("Stopped" )
272272
273273
274+ def _make_exception_handler (log ):
275+ """Return an asyncio exception handler that silences Windows WinError 10054
276+ noise from connection cleanup (ConnectionResetError in
277+ _ProactorBasePipeTransport._call_connection_lost), which is harmless but
278+ verbose on Python/Windows when a remote host force-closes a socket."""
279+ def handler (loop , context ):
280+ exc = context .get ("exception" )
281+ cb = context .get ("handle" ) or context .get ("source_traceback" , "" )
282+ if (
283+ isinstance (exc , ConnectionResetError )
284+ and "_call_connection_lost" in str (cb )
285+ ):
286+ return # suppress: benign Windows socket cleanup race
287+ log .error ("[asyncio] %s" , context .get ("message" , context ))
288+ if exc :
289+ loop .default_exception_handler (context )
290+ return handler
291+
292+
274293async def _run (config ):
294+ loop = asyncio .get_running_loop ()
295+ _log = logging .getLogger ("asyncio" )
296+ loop .set_exception_handler (_make_exception_handler (_log ))
275297 server = ProxyServer (config )
276298 try :
277299 await server .start ()
You can’t perform that action at this time.
0 commit comments