Debugging & Incident Diagnosis
Compatible with Cursor, Claude Code, Cline, Roo Code, Antigravity

Node.js & V8 Memory Leak / CPU Spike Investigation

Analyze heap snapshots, unclosed event listeners, and runaway closures causing Node.js OOM crashes.

Node.jsJavaScriptTypeScriptMemoryV8Performance
Skill Objective

Identify and resolve memory retainers, unclosed event listeners, runaway closures, and CPU event-loop blocking in Node.js services.

Execution Workflow Procedure

Ordered steps the coding agent executes when performing this skill.

1

Inspect Heap Retention Paths

Analyze heap snapshot metrics to trace which objects in Old Space are prevented from garbage collection.

2

Identify Leak Vectors

Inspect global maps, uncleared setInterval timers, lingering EventEmitter listeners, and stream backpressure bottlenecks.

3

Implement Weak References & AbortControllers

Refactor listeners to use AbortController signals and replace unbounded Maps with LRU caches or WeakMaps.

Agent Safety Guardrails & Anti-Hallucination Rules

  • DO NOT simply increase --max-old-space-size to hide a monotonic memory leak.
  • DO NOT perform CPU-intensive synchronous regex or crypto loops on the main Node.js event loop.

Expected Output Format

Leak retainer breakdown and leak-free refactored code.

🔍 Retain Tree Breakdown: Roots preventing garbage collection.
🛠️ Memory-Safe Refactoring: Cleaned listener and cache implementation.

Domain Verification Checks

Listener Lifecycle: Ensures listeners detach when connections close.
WeakMap Caching: Uses weak references for ephemeral object caches.
Stream Backpressure: Verifies high-volume streams handle pause/resume.

Example Agent Invocations

"Investigate why our WebSocket server crashes with exit code 137 every 4 hours."
"Profile this background event stream processing loop for memory leaks."

Install / Configure This Skill

# Place in .cursorrules or create .cursor/rules/nodejs-memory-leak-cpu-investigation.mdc
# Trigger: Whenever you perform node.js & v8 memory leak / cpu spike investigation

---
name: nodejs-memory-leak-cpu-investigation
description: Diagnose Node.js heap leaks, unclosed event listeners, and event-loop blocking issues.
version: 1.0.0
compatibility: [Cursor, Claude Code, Cline, Roo Code, Antigravity]
---

# Node.js & V8 Memory Leak / CPU Spike Investigation

## Objective
Detect and eliminate memory retainers, uncleaned event listeners, and event loop blocking operations in Node.js applications.

## Workflow
1. **Retainer Analysis**: Identify objects accumulating in V8 Old Space from heap snapshots.
2. **Leak Vector Elimination**: Remove lingering event listeners using `AbortController` and replace unbounded caches with TTL LRUs.
3. **Backpressure Validation**: Ensure streams respect pipeline backpressure.
Complementary Agent Prompt

Need a quick one-time prompt for chat?

Try the Node.js & V8 Memory Leak / CPU Spike Investigator — a lightweight version designed for 1-click copying directly into Claude, ChatGPT, or Cursor chat.

View Prompt

SprintKit Workflow Integrations

Complementary tools and checklists to pair with this agent workflow.

Related Agent Skills

Explore related procedural workflows in this discipline.

All Skills

API Performance Bottleneck & N+1 Query Optimization

Diagnose slow database queries, serialization bottlenecks, and memory churn in sluggish API endpoints.

PerformanceSQLNode.js+3
3 workflow stepsView skill

Production Exception & Stack Trace Root-Cause Analysis

Systematic investigation workflow for diagnosing production exceptions and constructing verified patches.

DebuggingObservabilityLogs+2
4 workflow stepsView skill

Strict TypeScript Type Safety & Soundness Audit

Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary validation.

TypeScriptNode.jsClean Code+1
4 workflow stepsView skill