RFR: 8330940: Impossible to create a socket backlog greater than 200 on Windows 8+ [v2]

Jaikiran Pai jpai at openjdk.org
Mon Jun 16 09:56:28 UTC 2025


On Mon, 16 Jun 2025 09:44:13 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Can I please get a review of this change which proposes to enhance the implementation of `ServerSocket` and `ServerSocketChannel` to allow for `backlog` values to be greater than 200 on Windows? This addresses https://bugs.openjdk.org/browse/JDK-8330940.
>> 
>> As noted in that enhancement request, right now on Windows, if the backlog is specified to be more than 200, then Windows caps it to a platform internal `SOMAXCONN`. As noted in the documentation here https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen applications can increase that limit by using the `SOMAXCONN_HINT` macro. That macro then adjusts the value to be between 200 and 65535, thus allowing for a higher backlog of connections.
>> 
>> The commit in this PR uses this macro when the specified backlog is 200 or more. A new jtreg test has been introduced to verify this change. This test and other existing tests in tier1, tier2 and tier3 continue to pass.
>> 
>> A similar restriction on the backlog value applies in Linux too https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.rst#tcp-variables. But from what I can see, unlike Windows, it cannot be adjusted when calling `listen()`.
>
> Jaikiran Pai has updated the pull request incrementally with four additional commits since the last revision:
> 
>  - include a test for AsynchronousServerSocketChannel
>  - System.err instead of System.out
>  - trim down code comment
>  -  > 200 instead of >= 200

Hello Michael,

> Are you sure that Windows does cap the value currently to SOMAXCONN, if the parameter is > 200?

Yes, I verified that part. In fact this current test reproduces that behaviour (by failing), if you undo the source code change in this PR. Anything above 200 backlogged connections results in the next attempt getting a connect failure exception. For example, running this test against JDK 24 on Windows results in:


...
connection 200 established Socket[addr=localhost/127.0.0.1,port=yyyy,localport=xxxx]
connection attempt 201 failed: java.net.ConnectException: Connection refused: connect
LargeBacklogTest$BackloggedServer at 3e7acc7e completed
stopping server ServerSocket[addr=localhost/127.0.0.1,localport=xxxx]
200 connections successfully established
Exception in thread "main" java.lang.AssertionError: expected at least 237 successful connections for a backlog of 242, but only 200 were successful
        at LargeBacklogTest.main(LargeBacklogTest.java:75)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/25819#issuecomment-2975879184


More information about the net-dev mailing list