Detects node eventloop block and reports where it started
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test fix tests on Windows Dec 14, 2017
.gitignore Initial commit Aug 25, 2017
.travis.yml add new node versions to travis config Jun 3, 2018 add contributing doc Nov 14, 2017
LICENSE Initial commit Aug 25, 2017
index.js asyncHook.disable was pointing to the wrong object Jul 18, 2018
package-lock.json regenerate package-lock Aug 31, 2018

blocked-at Build Status Greenkeeper badge

Detects slow synchronous execution and reports where it started.


Requires Node 8+

$ npm install blocked-at


blocked((time, stack) => {
  console.log(`Blocked for ${time}ms, operation started here:`, stack)


The blocked() function reports every value over the configured threshold (defaults to 20ms). Usage is similar to blocked but the detection mechanism is different, to allow pointing to the slow function.

It uses Async Hooks to measure the time and generate the stack trace. Stack trace will point to the beginning of an asynchronously called function that contained the long operation.

Run tests (npm test) to see examples.

Params and return value

const blocked = require('blocked-at')
const { stop } = blocked(fn, options)
  • fn: The callback function to execute when a function called asynchronously ran more than threshold. Two arguments are passed: time it measured and an array of stack frames (callstack)
  • options: Optional.
option default description
trimFalsePositives falsy eliminate a class of false positives (experimental)
threshold 20 minimum miliseconds of blockage to report. supported for parity with blocked
debug falsy print debug data to console

Returns: An object with stop method. stop() will disable the async hooks set up by this library and callback will no longer be called.

Using the stack trace

The stack trace is pointing to a start of a function called asynchronously, so in most cases the first stack frame pointing to your code is where you need to start analyzing all synchronous operations to find the slow one.

In some cases your code is not directly called and tracking it down will still be difficult. See how the http test case produces a stack pointing to Server.connectionListener as the slow function, because everything inside of it is synchronously called. You can always wrap your handlers' code in setImmediate if you become desperate.