Skip to content

Lesson 9 of 9 · 28m

Production Incident Debugging: Dumps, Diagnostics, and Safe Restarts

Build a disciplined incident workflow using diagnostics reports, heap snapshots, signals, logging, and restart decisions that preserve evidence before destroying it.

The first instinct during a Node outage is to restart the process. Sometimes that is right; availability matters. But a blind restart destroys the exact evidence that would have told you why the process wedged. Senior production debugging is a sequencing problem: preserve evidence cheaply, restore service deliberately, then analyze without inventing a narrative.

Capture the cheap facts first

Before restarting, record basic runtime state:

ps -o pid,ppid,stat,%cpu,%mem,rss,etime,cmd -p "$NODE_PID"
ls -l "/proc/$NODE_PID/fd" | wc -l

In containers, capture cgroup CPU throttling and memory events too. A process can look healthy inside its own metrics while the kernel is throttling it into uselessness.

Use the built-in diagnostic report

Node can produce a process diagnostic report with runtime state, environment, handles, and native stack context. Enable it deliberately:

node --report-on-signal --report-signal=SIGUSR2 server.js  # then: kill -USR2 "$NODE_PID"

The report is JSON and usually lands in the working directory unless --report-directory is set. It is not a complete memory or CPU profile, but it is fast, low-risk, and often enough to distinguish handle buildup, native crashes, and obvious environment mistakes.

Heap snapshots are heavier but decisive

Use --heapsnapshot-signal where supported or trigger snapshots through the inspector in a controlled way. Heap capture pauses the application and can consume significant disk and memory. In production, capture from one replica after removing it from rotation, not from the only live process serving customers.

Run the service with --heapsnapshot-signal=SIGUSR2 when this evidence is part of the runbook. Never overload the same signal for report and heap capture unless you know exactly which behavior you configured.

Know the restart ladder

A good incident runbook separates actions:

observe       metrics, logs, open files, thread count
capture       report/profile/snapshot if safe
drain         remove replica from load balancer
restart       supervisor or orchestrator action
verify        readiness, error rate, memory baseline
analyze       compare evidence after service restoration

Restart is one step, not the whole incident response. If the process is already unresponsive and causing customer impact, restore service first — but capture whatever is cheap before doing it.

Core dumps and native crashes are a separate game

If a native addon segfaults, JavaScript-level debugging is finished. Enable core dumps at the operating-system level where policy permits:

ulimit -c unlimited
node --abort-on-uncaught-exception server.js

Use this carefully. --abort-on-uncaught-exception is not a normal production switch because it trades process survival for postmortem completeness. For native crash analysis, preserve binary versions, dependency versions, kernel logs, and the exact core file.

Field notes

  • A heap snapshot is evidence and sensitive data at the same time; it can contain tokens, customer data, and request bodies. Handle it like a database dump.
  • If file descriptor count climbs, map descriptors to sockets and files before assuming a memory leak.
  • Post-incident, turn every manual diagnostic action into either an automated capture path or an explicit runbook decision.

Was this lesson helpful?

Sign in to rate