Repository navigation
Set TCP_NODELAY on accepted TCP connections - #255
Merged
Merged
Conversation
HTTPServer left Nagle's algorithm on for the sockets it accepts. A small write that follows another still unacknowledged, such as the next WebSocket message on a quiet connection, then waits for the client's ACK, which most stacks delay by up to 40 ms. On a WebSocket relaying a stream of small messages, about 2% of them arrived 40 to 42 ms late, each released by the client's delayed ACK. FlyingSocks gains a tcpNoDelay socket option (IPPROTO_TCP, TCP_NODELAY on every platform), and HTTPServer sets it on each connection it accepts on an IPv4 or IPv6 address. A Unix domain socket has no Nagle delay and is left alone; a failure to set it is logged as a warning and the connection is served anyway. HTTPConnection's socket is now internal so that a test can read the option back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEgKfBwi5LpKqwfbctCEdH
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
- Coverage 93.76% 93.75% -0.01%
==========================================
Files 72 72
Lines 3847 3859 +12
==========================================
+ Hits 3607 3618 +11
- Misses 240 241 +1 ☔ View full report in Codecov by Harness. |
swhitty
approved these changes
Nov 13, 2026
Owner
|
TIL! thank you for this I will merge it and then just extract the switch into its on func on main 🙏 |
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.
HTTPServerleaves Nagle's algorithm on for the sockets it accepts. When a small write follows one the client hasn't yet acknowledged, the kernel holds it until the ACK arrives, and most clients delay that ACK by up to 40 ms. Typical cases are the next WebSocket message on a quiet connection, or a response written in more than one piece.We noticed this on a WebSocket relaying a stream of small binary messages. About 2% of them reached the client 40 to 42 ms late, each one sent just after the client's delayed ACK. Most HTTP servers turn Nagle off on accepted connections for this reason; nginx's
tcp_nodelayis on by default, for example.This change:
tcpNoDelaysocket option (IPPROTO_TCP,TCP_NODELAY), with the two constants added to each platform'sSocketextension (Darwin, Glibc, Musl, Android, WinSock2).HTTPServer: sets the option on every connection it accepts on an IPv4 or IPv6 address.HTTPConnection:socketchanges fromprivateto internal, so a test can read the option back. Nothing else uses that.Tests:
SocketTests.socket_Sets_And_Gets_TCPNoDelayOptionround-trips the option on an IPv4 stream socket.HTTPServerTests.server_SetsTCPNoDelay_OnAcceptedConnectionschecks the option on the server's accepted connection. Without the server change it fails.HTTPDecoderTests'standardizedPathandnaughtyPath_IsParsed, which fail the same way onmain.IPPROTO_IPV6.rawValuepattern.If you'd rather make it a
Configurationflag than unconditional, I'm happy to change it.🤖 Generated with Claude Code
https://claude.ai/code/session_01CEgKfBwi5LpKqwfbctCEdH