RFR: 8329190: (ch) DatagramChannel.receive should throw ClosedChannelException when called on closed channel
Mark Sheppard
msheppar at openjdk.org
Tue Apr 16 12:10:26 UTC 2024
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.
-------------
Commit messages:
- JDK-8329190: DatagramChannel.receive should throw ClosedChannelException when called on closed channel - changes to ensure that a ClosedChannelException is consistently thrown when after a DatagramChannel has been closed via an asynchronous closed, or via interruption of calling thread. Thus, a DatagramChannel::receive call may throw an AsynchronousCloseException when another thread has closed the DatagramChannel, and it may throw a ClosedByInterruptException if its calling thread has been interrupted. In such scenario, a subsequent receive call on the DatagramChannel instance should result in a ClosedChannelException being thrown. The proposed changes (provided by Alan Bateman) strive to ensure that a ClosedChannelException is consistently thrown. The changes elevate the ensureOpen() method call, checking that the channel is open, to very early in the processing call flow of the read/write send/receive methods, in a number of Channel classes.
Changes: https://git.openjdk.org/jdk/pull/18796/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18796&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8329190
Stats: 226 lines in 6 files changed: 223 ins; 0 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/18796.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/18796/head:pull/18796
PR: https://git.openjdk.org/jdk/pull/18796
More information about the nio-dev
mailing list