Debugging & Incident Analysis
Target: Claude 3.7, Cursor, Windsurf, ChatGPT

Node.js & V8 Memory Leak / CPU Spike Investigator

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

Node.jsJavaScriptTypeScriptMemoryV8Performance

Interactive Prompt Playground

Customize Template Fields
Live replacement
{{CODE}}
{{HEAP_METRICS}}
{{NODE_VERSION}}
Rendered Prompt (Ready to paste)1304 characters
You are a Node.js Core and V8 Runtime Performance Architect.

Investigate a memory leak / out-of-memory (OOM) crash in this Node.js service:

Suspected Code / Background Workers:
```typescript
const cache = new Map();
const emitter = new EventEmitter();

export function registerClient(clientId, socket) {
  cache.set(clientId, { socket, history: [] });
  
  emitter.on('broadcast', (data) => {
    socket.write(JSON.stringify(data));
  });
}
```

Heap Snapshot / Metrics Observations:
```
Process restarts every 3 hours with Exit code 137 (OOM killer). Heap dump shows 800k EventEmitter listener closures retaining Socket objects.
```

Node.js Runtime & Heap Limit: Node.js 22 LTS, max-old-space-size=1024

Provide an engineering diagnostic:
1. **Memory Retainers & Leak Vectors**:
   - Identify what references (global maps, uncleared timers, lingering event listeners, closures holding outer scope) are preventing garbage collection.
2. **V8 Heap Mechanics**:
   - Explain how the retain tree grows in Old Space vs Young Space.
3. **Exact Code Fix**:
   - Provide the corrected code using `WeakMap`, proper `removeListener`, `AbortController`, or streaming streams.
4. **Diagnostic Commands**:
   - Give precise commands to profile this locally with `--inspect` and Chrome DevTools or `clinic doctor`.

How to Use This Prompt

  1. Paste the code for background workers, event listeners, or cache singletons.
  2. Describe memory growth patterns and heap metrics.
  3. Get a leak-free refactoring and debugging commands.

Engineering Tips & Best Practices

  • Use AbortController signals to automatically clean up multiple event listeners when a connection closes.

What This Prompt Inspects

Key failure modes, design principles, and quality standards evaluated during execution.

Listener Lifecycle

Ensures event listeners are detached when sockets or clients disconnect.

Weak References

Uses WeakMap or TTL-based LRU caches to allow automatic garbage collection.

Stream Backpressure

Verifies high-volume streams implement proper backpressure handling.

SprintKit Workflow Integrations

Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.

Related Prompts

Explore related developer prompts in this workflow domain.

All Prompts

API Performance Regression & N+1 Query Debugger

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

PerformanceSQLNode.jsJava+2
4 variablesCustomize prompt

Production Exception & Stack Trace Root-Cause Analyzer

Analyze production stack traces, error logs, and surrounding code using hypothesis-driven debugging.

DebuggingObservabilityLogsIncidents+1
4 variablesCustomize prompt

TypeScript Strict Type Safety & Clean Code Review

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

TypeScriptNode.jsClean CodeArchitecture