Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martin-tarjanyi opened this issue Feb 5, 2022 · 0 comments

Comments

@martin-tarjanyi
Copy link

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 #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant