fix(websocket): answer non-GET HTTP probes instead of 502 + error flood#6
Merged
Conversation
nanobot's gateway serves the WebUI through the websockets server, whose handshake parser only accepts GET. A HEAD probe (as a hosted load balancer or uptime monitor sends) made websockets abort the connection — the client got a 502 and a full traceback was logged at ERROR. On Render, something probes HEAD / roughly once per second, so the logs became a continuous wall of "opening handshake failed" tracebacks. Add a ServerConnection subclass that sniffs the first request line before the handshake is parsed: GET is handed to websockets unchanged (WS upgrades and every plain-HTTP WebUI route), HEAD gets an empty 200 so health checks stay green, and any other method gets 405. Answered probes are closed quietly, so nothing is logged at ERROR and the client never sees a 502. Wired via create_connection on serve()/unix_serve(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e constant Use stdlib %s lazy formatting for the debug log (self.logger here is the stdlib "websockets.server" logger, not nanobot's loguru logger), and reuse the existing OPENING_HANDSHAKE_FAILED_MESSAGE constant in the test instead of hardcoding the literal. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the Render deploy, the live service floods its logs with a full Python
traceback once per second:
Root cause: nanobot's
gatewayserves the WebUI through thewebsocketsserver, and that library's handshake parser only accepts
GET. Something(a hosted load balancer / uptime probe) sends
HEAD /~1×/second. The parserraises before nanobot's
process_requestruns, soconn_handlerlogs thefailure at ERROR with a traceback and aborts the TCP connection without a
response — the prober receives a 502.
Verified against the live service:
GET /→ 200 (WebUI works),HEAD /→ 502.Fix
Add a
ServerConnectionsubclass that sniffs the first request line beforethe handshake is parsed:
200(so platform health checks stay green)405 Allow: GETAnswered probes are closed quietly, so nothing is logged at ERROR and the
client never sees a 502. Wired via
create_connectiononserve()/unix_serve().Tests
tests/channels/test_websocket_head_probe.py: HEAD → 200, GET route → 200, POST → 405, and no"opening handshake failed"ERROR logged.🤖 Generated with Claude Code