RFR: 8358764: (sc) SocketChannel.close when thread blocked in read causes connection to be reset (win)
Alan Bateman
alanb at openjdk.org
Tue Jun 10 14:17:32 UTC 2025
On Tue, 10 Jun 2025 13:53:39 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
>> On Windows, if a platform thread is blocked in SocketChannel.read, and another thread closes the channel, then Windows abruptly closes the connection (RST). In releases prior to JDK 11, the connection was shutdown for writing before closing so the connection was closed gracefully, an unexpected behavior change
>>
>> implCloseBlockingMode is changed to shutdown the connection for writing on Windows, no change in behavior for other platforms.
>
> src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java line 1125:
>
>> 1123: state = ST_CLOSING;
>> 1124:
>> 1125: if (connected && Net.shouldShutdownWriteBeforeClose()) {
>
> Hello Alan, I just had a brief passing look at these changes and based on my limited knowledge of this area, they look reasonable to me. I'll take a more detailed look tomorrow. Is the use of a JNI function, to determine whether or not we should shutdown before close, done for the sake of consistency with the rest of the platform specific logic?
The NativeDispatcher and Net APIs are separate, the latter typically has very platform specific code to configure. So it's just keeping to the existing architecture.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25700#discussion_r2138026540
More information about the nio-dev
mailing list