BlockHound: detect blocking calls in Reactive code before it’s too late

Domenico Sibilio
4 min readSep 22, 2019

Find the blockage that clogs your reactive streams pipelines before it hits production!

The official Project Reactor logo

In the era of Reactive Programming, one of the most common concerns is to spot blocking calls and embed them properly in reactive code or replace them with a reactive alternative when possible.

It’s really easy to miss some of these blocking operations and end up shipping to production something that shouldn’t be considered production-ready at all: scheduling blocking calls inside non-blocking threads can lead to unpredictable behaviour, at best!

To avoid this happening to you, you should strongly consider relying on a tool like BlockHound to detect blocking calls in reactive code.

How does it work?

BlockHound acts similarly to a java agent, a special little piece of software that gets loaded by the JVM before invoking the main entry point of your application and relies on the JVM Instrumentation API to orchestrate byte-code manipulation on classes and redefine their behaviour.

Once BlockHound gets bootstrapped, it marks a set of blocking methods that need to be altered (eg.Thread.sleep()) and changes their behaviour so they’ll end up throwing an Error in case they get invoked from within a thread…

--

--

Domenico Sibilio
Domenico Sibilio

Written by Domenico Sibilio

Software Developer @ https://www.linkedin.com/in/dsibilio/ — If my articles helped you, consider buying me a coffee :) https://www.buymeacoffee.com/dsibilio

No responses yet