BlockHound icon indicating copy to clipboard operation
BlockHound copied to clipboard

`java.nio.channels.FileChannel` related operations are not detected as blocking

Open martin-tarjanyi opened this issue 3 years ago • 0 comments

Expected Behavior

BlockHound should report a blocking call for some java.nio.Files operations as FileChannel is used under the hood which is always blocking since it is not a SelectableChannel. Likely related to https://github.com/reactor/BlockHound/issues/192.

Actual Behavior

BlockHound does not detect blocking call.

Steps to Reproduce

@Test
void reproCase() {
    BlockHound.install();

    // not detected
    Flux.using(
            () -> Files.lines(Path.of("test/sample.txt")),
            Flux::fromStream,
            Stream::close
        ).subscribeOn(Schedulers.parallel())
        .blockLast();

    // not detected
    Mono.fromCallable(() -> Files.readAllLines(Path.of("test/sample.txt")))
        .subscribeOn(Schedulers.parallel())
        .block();
}

Possible Solution

I'm not sure these are the best methods to be marked as blocking but these solved this issue. Probably some write methods should be marked as blocking as well.

BlockHound.builder()
    .markAsBlocking("sun/nio/ch/FileChannelImpl", "read", "(Ljava/nio/ByteBuffer;)I")
    .markAsBlocking("java/nio/channels/FileChannel", "open",
        "(Ljava/nio/file/Path;Ljava/util/Set;[Ljava/nio/file/attribute/FileAttribute;)Ljava/nio/channels/FileChannel;")
    .with(new ReactorBlockHoundIntegration())
    .install();

// detected
Flux.using(
        () -> Files.lines(Path.of("test/sample.txt")),
        Flux::fromStream,
        Stream::close
    ).subscribeOn(Schedulers.parallel())
    .blockLast();

// detected
Mono.fromCallable(() -> Files.readAllLines(Path.of("test/sample.txt")))
    .subscribeOn(Schedulers.parallel())
    .block();

Your Environment

  • Reactor version(s) used: core: 3.4.14, blockhound: 1.0.6.RELEASE

martin-tarjanyi avatar Feb 05 '22 13:02 martin-tarjanyi