Skip to content

Commit d222b9d

Browse files
alireza787bclaude
andcommitted
fix(server): suppress Windows ProactorEventLoop connection cleanup noise
On Windows Python 3.10+, the ProactorEventLoop fires ConnectionResetError in _call_connection_lost when HTTP/WebSocket clients disconnect. Install a custom asyncio exception handler on the FastAPI server thread that downgrades these expected cleanup errors to DEBUG level, eliminating log spam while preserving all other exception reporting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 75b33ab commit d222b9d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/classes/flow_controller.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,33 @@ def start_fastapi_server(self):
7171

7272
# Start the FastAPI server using the async start method
7373
def run_server():
74-
asyncio.run(fastapi_handler.start(
74+
loop = asyncio.new_event_loop()
75+
asyncio.set_event_loop(loop)
76+
77+
# Suppress Windows ProactorEventLoop ConnectionResetError noise.
78+
# On Windows, the Proactor transport fires _call_connection_lost
79+
# when clients disconnect (browser tab close, WebSocket drop).
80+
# The socket is already dead — the cleanup error is harmless.
81+
if platform.system() == "Windows":
82+
_default_handler = loop.get_exception_handler()
83+
84+
def _windows_exception_handler(loop, context):
85+
exception = context.get("exception")
86+
if isinstance(exception, ConnectionResetError):
87+
logger.debug(
88+
"Suppressed Windows Proactor connection cleanup: %s",
89+
context.get("message", ""),
90+
)
91+
return
92+
# Delegate everything else to the default handler
93+
if _default_handler is not None:
94+
_default_handler(loop, context)
95+
else:
96+
loop.default_exception_handler(context)
97+
98+
loop.set_exception_handler(_windows_exception_handler)
99+
100+
loop.run_until_complete(fastapi_handler.start(
75101
host=Parameters.HTTP_STREAM_HOST,
76102
port=Parameters.HTTP_STREAM_PORT
77103
))

0 commit comments

Comments
 (0)