RFR: 8329190: (ch) DatagramChannel.receive should throw ClosedChannelException when called on closed channel
    Jaikiran Pai 
    jpai at openjdk.org
       
    Tue Apr 16 12:55:41 UTC 2024
    
    
  
On Tue, 16 Apr 2024 12:03:07 GMT, Mark Sheppard <msheppar at openjdk.org> wrote:
> Please oblige and review the following changes (provided by Alan Bateman) which addresses the issue outlined in
> JDK-8329190: DatagramChannel.receive should throw ClosedChannelException when called on closed channel 
> 
> This ensures that a ClosedChannelException is consistently thrown from DatagramChannel send and receive methods, especially in the context of asynchronous closure and calling thread interruption.
> 
> The change is to move the ensureOpen() method call, which checks that a channel has not been closed, to the start of read/write send/receive methods on the DatagramChannel
> 
> The regression suites for jdk_nio and jdk_net and the JCK tests for api/java_nio api/java_net have been executed in repeat mode, multiple times, without any observed relevant failures.
src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java line 395:
> 393:         acceptLock.lock();
> 394:         try {
> 395:             ensureOpen();
Hello Mark, I think this may not be needed, especially since it's being called without synchronizing on `stateLock`. A couple of lines below this line, there's a call to `begin(blocking)` and the implementation of `begin()` already calls the `ensureOpen()` after acquiring a `stateLock` first.
src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java line 958:
> 956:                 writeLock.lock();
> 957:                 try {
> 958:                     ensureOpen();
Similar comment as that for `ServerSocketChannelImpl`, the `beginConnect()` call a few lines below already does a `ensureOpen()` after acquiring the `stateLock` monitor.
src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java line 1057:
> 1055:                         return true;
> 1056: 
> 1057:                     ensureOpen();
Likewise, `beginFinishConnect()` already has the ensureOpen()
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18796#discussion_r1567303316
PR Review Comment: https://git.openjdk.org/jdk/pull/18796#discussion_r1567307989
PR Review Comment: https://git.openjdk.org/jdk/pull/18796#discussion_r1567308912
    
    
More information about the nio-dev
mailing list