Skip to content
Java agent to detect blocking calls from non-blocking threads.
Branch: master
Clone or download
Latest commit e98e2db Mar 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
agent https all the things! Mar 20, 2019
docs https all the things! Mar 20, 2019
example https all the things! Mar 20, 2019
gradle/wrapper Java agent implementation (#2) Jan 14, 2019
junit-platform Add FIXME about the `testRuntime` Mar 19, 2019
native-agent https all the things! Mar 20, 2019
.gitignore Initial documentation (#7) Feb 1, 2019
.travis.yml
LICENSE https all the things! Mar 20, 2019
README.md
build.gradle change group to `io.projectreactor.tools` Feb 4, 2019
gradlew
gradlew.bat
settings.gradle Integrate with JUnit Platform (#13) Mar 19, 2019

README.md

BlockHound (experimental)

Travis CI

Java agent to detect blocking calls from non-blocking threads.

How it works

BlockHound will transparently instrument the JVM classes and intercept blocking calls (e.g. IO) if they are performed from threads marked as "non-blocking operations only" (ie. threads implementing Reactor's NonBlocking marker interface, like those started by Schedulers.parallel()). If and when this happens (but remember, this should never happen!😜), an error will be thrown. Here is an example:

// Example.java
BlockHound.install();

Mono.delay(Duration.ofSeconds(1))
    .doOnNext(it -> {
        try {
            Thread.sleep(10);
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    })
    .block();

Will result in:

java.lang.Error: Blocking call! java.lang.Thread.sleep
	at java.base/java.lang.Thread.sleep(Native Method)
	at com.example.Example.lambda$exampleTest$0(Example.java:16)

Note that it points to the exact place where the blocking call got triggered. In this example it was Example.java:16.

Getting it

Download it from Maven Central repositories (stable releases only) or repo.spring.io:

repositories {
  maven { url 'https://repo.spring.io/milestone' }
  // maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
  testCompile 'io.projectreactor.tools:blockhound:$LATEST_RELEASE'
  // testCompile 'io.projectreactor.tools:blockhound:$LATEST_SNAPSHOT'
}

Where:

$LATEST_RELEASE
$LATEST_SNAPSHOT

Quick Start

See the docs.


Licensed under Apache Software License 2.0

Sponsored by Pivotal

You can’t perform that action at this time.