From cf4856928f0d6aa5805984c04b169ac9451d5e27 Mon Sep 17 00:00:00 2001 From: emranemran Date: Thu, 11 Jun 2026 13:57:25 -0700 Subject: [PATCH] fix(ws): filter the websockets handshake-probe traceback flood MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Non-WebSocket connections to the port (health probes, port scanners, the tunnel's TCP checks) fail the WS handshake and websockets logs a full InvalidMessage/EOFError traceback — ~2k per pod per session of pure noise. They fail before `_process_request`, so the HTTP short-circuit can't catch them. Add a logging.Filter on the `websockets.server` logger that drops the `opening handshake failed` record (logged on that logger directly, no per-connection child, so one filter catches all). Real handler failures log a different message (`connection handler failed`) and still surface. Co-Authored-By: Claude Opus 4.8 (1M context) --- demos/realtime_motion_graph_web/server.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/demos/realtime_motion_graph_web/server.py b/demos/realtime_motion_graph_web/server.py index 39cff52a..a0662621 100644 --- a/demos/realtime_motion_graph_web/server.py +++ b/demos/realtime_motion_graph_web/server.py @@ -17,6 +17,7 @@ """ import json +import logging import mimetypes import os import sys @@ -476,11 +477,27 @@ def _stub_handle_client(ws): pass +class _DropHandshakeNoise(logging.Filter): + """Drop the `opening handshake failed` records websockets logs for every + non-WebSocket connection that hits the port — health probes, port + scanners, the tunnel's TCP checks. Each is a full InvalidMessage/EOFError + traceback (~2k per pod per session) and never actionable. Real failures + log a different message (`connection handler failed`) and pass through. + """ + + def filter(self, record: logging.LogRecord) -> bool: + return record.getMessage() != "opening handshake failed" + + def main(): # Wire logging FIRST so even the CLI-arg validation prints flow through # the configured sinks. configure() is idempotent so a duplicate call # in any nested entry point is a no-op. configure_logging() + # Silence the handshake-failure traceback flood from port probes. The + # record is logged directly on `websockets.server` (not a per-connection + # child), so a filter on that logger catches every one. + logging.getLogger("websockets.server").addFilter(_DropHandshakeNoise()) host = "0.0.0.0" port = 1318 # single port: serves both HTTP and WebSocket