Skip to main content

Hangs

Beta

This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas.

A hang is a stretch of time in which the event loop is blocked. A synchronous loop, a huge JSON.parse or a blocking call keeps every request of the process waiting, and nothing is thrown, so no crash detector can see it. Bugsee detects it with a watchdog and reports it as an error.

Hang detection runs on Node.js and Bun. It is on by default.

How it works​

The main thread writes a heartbeat into a shared buffer about once a second. A separate watchdog worker thread reads that buffer. A blocked event loop cannot write, so the heartbeat goes stale, and the worker notices.

The worker is unref'd, so it never keeps a process alive. It uses about 12 MB of memory on Node.js and about 5 MB on Bun in our measurements, with negligible CPU.

Thresholds and levels​

A hang escalates through three levels as it gets longer. Each level reports once per hang. When the loop recovers, the detector re-arms, so a service that hangs again later reports again.

LevelOptionDefaultDomain
FairhangFairMs3000AppHang::Fair
MediumhangMediumMs5000AppHang::Medium
SeverehangSevereMs10000AppHang::Severe

The thresholds must be positive and strictly increasing. If they are not, Bugsee falls back to the defaults for all three.

OptionTypeDefaultDescription
detectHangsbooleantrueTurn hang detection on or off.
hangFairMsnumber3000Stall length of the first level, in milliseconds.
hangMediumMsnumber5000Stall length of the second level.
hangSevereMsnumber10000Stall length of the third level.
import { launch } from '@bugsee/bugsee';

launch('<your_app_token>', {
hangFairMs: 1000,
hangMediumMs: 3000,
hangSevereMs: 8000,
});

The report​

FieldValue
TypeError, with the error priority (reportDefaultErrorPriority)
SummaryMain thread hang detected
DescriptionEvent loop blocked for <n>ms (AppHang::Fair), with the level of the report
LabelThe domain, for example AppHang::Fair

Get the blocking stack​

Nothing throws during a hang, so the report has no stack of its own. V8 keeps sampling while the loop is blocked, so the CPU profile of the stall shows where the code was stuck.

Turn on profiling to use it:

launch('<your_app_token>', {
profiling: true,
});

With profiling on, Bugsee takes the hottest stack of the stall window from the profile and attaches it to the hang report as its stack frames. Hangs are then grouped by where they block, and the report carries a profile.json as well. The profile is rolling, covers the last maxRecordingTime seconds, and opens in Chrome DevTools or speedscope.

If the profile is not ready within five seconds, the report goes out without frames.

Without profiling, every hang of a given level has the same signature, such as AppHang::Fair, and they are all grouped together. See Diagnostics for the profiler options and their cost.

Not covered​

  • Browsers have no hang detector in this SDK.
  • Cloudflare, Vercel Edge and worker runtimes do not run the watchdog.
Found an issue, typo, or wrong statement on this page? Report it now →