On Wed, 6 May 2026 13:46:48 GMT, Jaikiran Pai <[email protected]> wrote:

>> Jaikiran Pai has updated the pull request with a new target base due to a 
>> merge or a rebase. The incremental webrev excludes the unrelated changes 
>> brought in by the merge/rebase. The pull request contains six additional 
>> commits since the last revision:
>> 
>>  - Reword the shutdownInput/Output and isInput/OutputShutdown() methods
>>  - merge latest from master branch
>>  - merge latest from master branch
>>  - link instead of linkplain
>>  - improve the text
>>  - 8310138 Socket.isInputShutdown and isOutputShutdown don't specify what is 
>> returned when socket is closed
>
> src/java.base/share/classes/java/net/Socket.java line 1667:
> 
>> 1665:      * <p>
>> 1666:      * If you write to a socket {@code OutputStream} after invoking 
>> this method,
>> 1667:      * the stream will throw an {@code IOException}.
> 
> A separate detail we might want to discuss is whether the `NioSocketImpl` in 
> its write() implementation should detect a `isOutputClosed` and throw an 
> `IOException` from the Java code instead of issuing a native write call and 
> then throwing the exception from there. What I mean is, in the current 
> implementation, it's the native code which throws this IOException. Here's an 
> example:
> 
> 
> jshell> var s = new Socket("127.0.0.1", 8000)
> s ==> Socket[addr=/127.0.0.1,port=8000,localport=12345]
> 
> jshell> OutputStream os = s.getOutputStream()
> os ==> java.net.Socket$SocketOutputStream@3830f1c0
> 
> jshell> s.shutdownOutput()
> 
> jshell> os.write(0x42)
> |  Exception java.net.SocketException: Broken pipe
> |        at SocketDispatcher.write0 (Native Method)
> |        at SocketDispatcher.write (SocketDispatcher.java:65)
> |        at NioSocketImpl.tryWrite (NioSocketImpl.java:408)
> |        at NioSocketImpl.implWrite (NioSocketImpl.java:425)
> |        at NioSocketImpl.write (NioSocketImpl.java:458)
> |        at NioSocketImpl$2.write (NioSocketImpl.java:825)
> |        at Socket$SocketOutputStream.implWrite (Socket.java:1097)
> |        at Socket$SocketOutputStream.write (Socket.java:1087)
> |        at Socket$SocketOutputStream.write (Socket.java:1082)
> |        at (#11:1)

I think the current implementation is okay. It could, as you suggest, check 
isOutputClosed but that is set asynchronously so would race with 
shutdownOutput. The benefit of what we have now is that we get the error 
message from the operating system.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31000#discussion_r3196448974

Reply via email to