On Thu, 5 Feb 2026 11:06:16 GMT, Daniel Fuchs <[email protected]> wrote:

>> Yes. See the following snippet:
>> 
>> 
>> var s0 = new ServerSocket(0, 1, InetAddress.getLoopbackAddress()); // note 
>> backlog=1
>> var s1 = new Socket(s0.getInetAddress(), s0.getLocalPort());
>> // Following line
>> // - works on Linux
>> // - fails on Windows with `java.net.ConnectException: Connection refused: 
>> connect`
>> // - fails on macOS with `java.net.ConnectException: Operation timed out`
>> var s2 = new Socket(s0.getInetAddress(), s0.getLocalPort());
>> 
>> 
>> OS versions:
>> 
>> - Oracle Linux 8 (amd64)
>> - Windows Server 2022 10.0 (amd64)
>> - Mac OS X 15.7 (x86_64)
>> 
>> I will privately share the JTreg logs with you.
>
> OK - this is because the OS specific timeout kicks in. So you might get a 
> `ConnectException` if the timeout you provide to connect() exceeds the 
> OS/platform specific timeout. Otherwise you get the `SocketTimeoutException`. 
> In my experiment (from which I excluded windows), I never got to trigger the 
> `ConnectException`. I was using a timeout of `250 + 
> Utils.adjustTimeout(250)`. It's OK to keep the `ConnectException` then. But 
> I'm still wondering: does 5000 trigger the ConnectException?

I'd expect the default OS specific connection timeout to be around 2 mins on 
unix platforms. So if you pass a timeout that's largely lesser than that you 
will practically never see the `ConnectException`. It may still happen if the 
selector/poller thread is paused for too long, so it's good to cater for that.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29431#discussion_r2768503128

Reply via email to