Skip to content

Overview ​

While synchronous code runs — a huge JSON.parse, a CPU-heavy loop, a sync filesystem call — Node can't do anything else: every request the process is handling stalls, yet nothing throws. eventLoopBlockIntegration notices such stalls and sends a warn-level log for each one:

Event loop blocked for 1840ms

with the stall's length in the duration attribute. It's the server-side counterpart of the browser's slowHandlerIntegration.

It works with a lightweight timer that checks whether it fired late. The timer never keeps the process alive on its own.

Usage ​

ts
import { use } from '@buglapse/node'
import { eventLoopBlockIntegration } from '@buglapse/node/integrations'

use(eventLoopBlockIntegration())

// report shorter stalls too:
use(eventLoopBlockIntegration({ threshold: 200 }))

Options ​

OptionTypeDefaultDescription
thresholdnumber1000Shortest stall, in ms, that's reported

The log says that the loop was blocked and for how long, not what blocked it. To find the culprit, look at the traces around that time, or profile the process.