Repository navigation
Add handshake and idle read timeouts to WebSockets.listen! - #1491
Merged
Merged
Conversation
The WebSocket server had no timeouts and no way to set one, so a client that connected and never finished the handshake, or went silent after it, held a task and a socket for as long as it liked. WebSockets.listen! (and serve!) now take read_header_timeout, read_timeout and idle_timeout, in seconds or as _ns values, with HTTP.serve!'s meaning and its off-by-default values: read_header_timeout bounds the handshake request, idle_timeout closes a session on which nothing arrives for that long, and both fall back to read_timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1491 +/- ##
==========================================
+ Coverage 91.12% 91.68% +0.56%
==========================================
Files 31 31
Lines 12535 13208 +673
==========================================
+ Hits 11422 12110 +688
+ Misses 1113 1098 -15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # CHANGELOG.md
Merged
quinnj
referenced
this pull request
Oct 22, 2026
URIs 1.7.2 rejects "http://[::1]evil.com/" when building the URI, so the test now accepts either rejection; with older URIs the URI still parses and HTTP must throw ArgumentError. Test-only change. Co-Authored-By: Claude Opus 5.5 <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.
WebSockets.listen!had no timeouts and no way to set one. A client that connected and never finished its handshake, or went silent after it, held a task and a socket for as long as it liked.WebSockets.listen!, andWebSockets.serve!with it, now takeread_header_timeout,read_timeoutandidle_timeout, in seconds or as_nsvalues, with the meaning and off-by-default values they have inHTTP.serve!:read_header_timeoutsets a read deadline from accepting the connection to the end of the upgrade request. That covers the TLS handshake on awssserver.idle_timeoutbecomes the session's read idle timeout. The read loop already supports that timeout, re-arming it before each read and closing with 1006websocket read idle timeoutwhen it expires.read_timeoutwhen they are0, as inHTTP.serve!.Passing a value in both seconds and
_nsform throwsArgumentError, via the same helperserve!uses. The defaults stay0(off). Whether to turn them on is a separate decision.Verification. New testset in
test/http_websocket_server_tests.jlthat uses already-expired 1 ns timeouts. Withread_header_timeout_ns = 1, a client that sends nothing is disconnected. Withidle_timeout_ns = 1, the handler'sreceivethrowsWebSocketErrorwith reasonwebsocket read idle timeout. On master the keywords do not exist.http_websocket_server_tests.jl(68) andhttp_websocket_integration_tests.jlpass locally.Review. The handshake deadline is cleared right after the request is read, so a slow handler or the session is not cut by it. The idle timeout goes through the
read_idle_timeout_nsfield that the client'sread_idle_timeoutalready uses, so both sides share one code path.HTTP.listen!withWebSockets.upgradeis unchanged: the HTTP server's own deadlines apply there untilupgradeclears them. This PR and #1482 both edit_serve_ws_conn!aroundread_request, so whichever merges second needs a small rebase.🤖 Generated with Claude Code