Skip to content

[BUG] EventEmitter memory leak: drain listeners accumulate on Socket during long sessions #391

@BryanDang

Description

@BryanDang

Environment

  • Desktop Commander version: 0.2.38
  • Node.js version: v24.3.0
  • OS: macOS 15.7.4 (Sequoia)
  • Claude Desktop (installed via npx -y @wonderwhy-er/desktop-commander@latest)

Description

During extended Claude Desktop sessions with heavy tool usage (50+ tool calls), Desktop Commander accumulates drain event listeners on its stdio Socket without cleanup. Once the count exceeds the default MaxListeners threshold of 10, Node emits MaxListenersExceededWarning. As the session continues, responsiveness degrades and tool calls begin timing out with no response returned to the client.

To Reproduce

  1. Start Claude Desktop with Desktop Commander configured
  2. Run a session with sustained tool usage — mix of read_file, list_directory, start_process, edit_block (roughly 50+ calls)
  3. Observe MCP debug log at ~/Library/Logs/Claude/mcp-server-desktop-commander.log

Expected Behavior

Listener count on the stdio Socket stays bounded regardless of session length. Tool calls remain responsive throughout.

Actual Behavior

After approximately 10+ tool interactions, the following warning appears in the MCP log:

(node:1189) MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 drain listeners added to [Socket]. MaxListeners is 10.
Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

The warning recurs throughout the session (observed at 06:01, 17:45, and 18:53 UTC in a single day). After extended use, tool calls begin returning empty responses (the Claude Desktop client reports "No result received from client-side tool execution").

Restarting Claude Desktop (which respawns the DC process) resolves the issue until the listener count accumulates again.

Log Evidence

Three occurrences from a single session on 2026-03-23:

2026-03-23T06:01:11.497Z [info] [desktop-commander] Message from server:
{"jsonrpc":"2.0","method":"notifications/message","params":{"level":"error","logger":"desktop-commander",
"data":"(node:1189) MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 drain listeners added to [Socket]. MaxListeners is 10. ..."}}

2026-03-23T17:45:24.737Z [info] [desktop-commander] Message from server:
{"jsonrpc":"2.0","method":"notifications/message","params":{"level":"error","logger":"desktop-commander",
"data":"(node:1189) MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 drain listeners added to [Socket]. MaxListeners is 10. ..."}}

2026-03-23T18:53:02.531Z [info] [desktop-commander] Message from server:
{"jsonrpc":"2.0","method":"notifications/message","params":{"level":"error","logger":"desktop-commander",
"data":"(node:1189) MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 drain listeners added to [Socket]. MaxListeners is 10. ..."}}

Additional Context

  • The leak is specifically drain listeners on [Socket], suggesting the stdio transport layer adds listeners per-request without removing them on completion.
  • The issue compounds over time — sessions with fewer tool calls may never hit the threshold.
  • Workaround: restart Claude Desktop periodically to reset the DC process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions