`java.nio.channels.FileChannel` related operations are not detected as blocking
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.5k
- Forks
- 95
- Avg merge
- 1d 14m
- Merged PRs (30d)
- 6
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproCase examples and compare their behavior with the proposed BlockHound.builder markAsBlocking entries. Inspect how ReactorBlockHoundIntegration configures BlockHound. Done means the Files.lines and Files.readAllLines calls on parallel schedulers are reported as blocking, with relevant write methods considered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100