[Windows] Stop silently dropping TCP_NODELAY - #3707
Open
jakepetroules wants to merge 1 commit into
Open
jakepetroules wants to merge 1 commit into
jakepetroules wants to merge 1 commit into
Conversation
`BaseSocket.setOption` refuses to set `TCP_NODELAY` on sockets whose protocol family is not IP, because doing so fails on UNIX domain sockets. It determined the family from `try? self.localAddress().protocol`, treating a failure to answer as "not an IP socket" and returning without setting anything. On Windows that discards the option every time. Winsock fails `getsockname` for a socket that has not been bound yet, where POSIX reports the wildcard address, and channel options are applied before the socket is bound or connected. Both `ClientBootstrap` and `ServerBootstrap` enable `TCP_NODELAY` by default, so in practice Nagle's algorithm stayed on for every NIO TCP channel on Windows. Ask the socket for its address family instead of deriving it from an address it may not have yet: Winsock reports it in the `WSAPROTOCOL_INFOW` returned by `SO_PROTOCOL_INFOW`. Other platforms keep using the local address exactly as before. This fixes `ChannelTests.testTCP_NODELAYisOnByDefaultForInetSockets` and `testTCP_NODELAYisOnByDefaultForInet6Sockets`, which observed the option reading back as 0 on Windows.
jakepetroules
force-pushed
the
windows-tcp-nodelay
branch
from
September 8, 2026 07:05
9f2f485 to
4491053
Compare
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.
BaseSocket.setOptiondid not setTCP_NODELAYon Windows, because it determines the socket family usinglocalAddress().protocol, which fails for unbound Winsock sockets becausegetsocknamerequires the socket to be bound.Since NIO applies options before bind/connect, the option was silently dropped.
This PR changes it to get the socket family directly from
SO_PROTOCOL_INFOW/WSAPROTOCOL_INFOWso thatTCP_NODELAYis correctly applied on Windows. (Other platforms continue using the local address, so behavior is unchanged)ChannelTests.testTCP_NODELAYisOnByDefaultForInetSocketsandtestTCP_NODELAYisOnByDefaultForInet6Socketsare now fixed.