From e521b0a7cf078eb111822843292281d7574552f9 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Sat, 25 Apr 2026 02:49:42 +0330 Subject: [PATCH] fix: suppress benign Windows socket cleanup errors in asyncio --- main.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.py b/main.py index 1fb76a8..e148a69 100644 --- a/main.py +++ b/main.py @@ -271,7 +271,29 @@ def main(): log.info("Stopped") +def _make_exception_handler(log): + """Return an asyncio exception handler that silences Windows WinError 10054 + noise from connection cleanup (ConnectionResetError in + _ProactorBasePipeTransport._call_connection_lost), which is harmless but + verbose on Python/Windows when a remote host force-closes a socket.""" + def handler(loop, context): + exc = context.get("exception") + cb = context.get("handle") or context.get("source_traceback", "") + if ( + isinstance(exc, ConnectionResetError) + and "_call_connection_lost" in str(cb) + ): + return # suppress: benign Windows socket cleanup race + log.error("[asyncio] %s", context.get("message", context)) + if exc: + loop.default_exception_handler(context) + return handler + + async def _run(config): + loop = asyncio.get_running_loop() + _log = logging.getLogger("asyncio") + loop.set_exception_handler(_make_exception_handler(_log)) server = ProxyServer(config) try: await server.start()