RFR: 8310902: (fc) FileChannel.transferXXX async close and interrupt issues

Brian Burkhalter bpb at openjdk.org
Tue Jun 27 06:09:36 UTC 2023


On Mon, 26 Jun 2023 17:14:15 GMT, Alan Bateman <alanb at openjdk.org> wrote:

> This change fixes a number of bugs with FileChannel.transferTo/transerFrom that arise when the source or target channel is closed, or the thread is interrupted, during the transfer. More specifically:
> 
> - The direct implementations operate on the raw file descriptor and don't prevent the target/source channel from being closed during the transfer. For this PR, the direct transferTo is limited to cases where the target is a FileChannel or SocketChannel. It could be extended to other SelChImpl implementations (SinkChannel, DatagramChannel) if needed, but they are less interesting at this time.
> 
> - The transferTo/transferFrom methods are specified to throw ClosedByInterruptException after closing both channels. This is implemented inconsistently, and leaves one channel open in several cases.

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 547:

> 545:     }
> 546: 
> 547:     // Assume at first that the underlying kernel supports sendfile();

It's not just sendfile() any more so maybe this comment should be broadened.

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 552:

> 550:     private static volatile boolean transferToDirectNotSupported;
> 551: 
> 552:     // Assume that the underlying kernel sendfile() will work if the target

This comment could be broadened as well.

test/jdk/java/nio/channels/FileChannel/CloseDuringTransfer.java line 194:

> 192:     @ParameterizedTest
> 193:     @MethodSource("sources")
> 194:     void testInterruptTransferDuring(ReadableByteChannel src) throws Exception {

I think this method must've been intended to be named `testInterruptDuringTransferFrom`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14656#discussion_r1242889248
PR Review Comment: https://git.openjdk.org/jdk/pull/14656#discussion_r1242889487
PR Review Comment: https://git.openjdk.org/jdk/pull/14656#discussion_r1242866175


More information about the nio-dev mailing list