Memory leak: MaxListenersExceededWarning - 11+ abort listeners on AbortSignal

Resolved 💬 5 comments Opened Jun 26, 2025 by Paramonov86 Closed Aug 21, 2025

Issue Description

Getting persistent MaxListenersExceededWarning when using Claude Code CLI:

(node:451) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 abort listeners added to [AbortSignal]. MaxListeners is 10. Use events.setMaxListeners() to increase limit

Root Cause Analysis

The issue appears to be in the HTTP request handling code where multiple abort event listeners are being added to the same AbortSignal instance without proper cleanup, particularly in scenarios involving:

  1. Request retry logic
  2. Concurrent operations
  3. Error handling paths where cleanup handlers don't execute properly

Expected Behavior

AbortController/AbortSignal instances should have proper lifecycle management with cleanup of event listeners.

Actual Behavior

Multiple abort listeners (11+) accumulate on the same AbortSignal instance, triggering Node.js memory leak warnings.

Environment

  • Platform: WSL2 Linux
  • Node.js version: Latest
  • Claude Code CLI: Latest version

Temporary Workaround

Currently users need to set export NODE_NO_WARNINGS=1 to suppress the warnings, but this masks the underlying memory management issue.

Suggested Fix

Implement proper AbortController lifecycle management:

  • Create new AbortController for each operation
  • Ensure explicit cleanup of event listeners
  • Consider using AbortSignal.timeout() for time-based operations
  • Add request deduplication to prevent multiple listeners on same signal

Impact

This affects user experience as the CLI starts with warning messages, and potentially indicates real memory leaks in long-running sessions.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗