Symptom
Local stdio MCP servers that write to stderr produce MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [WriteStream]. MaxListeners is 10.
Evidence what you'll see
StdioClientTransport.start()attaches listeners on stdinerror, stdoutdataanderror, andthis._process.stderr.pipe(this._stderrStream), which adds adrainlistener.close()kills the process and does notunpipeorremoveAllListeners.- Minimal servers that produce no stderr do not trigger the warning. Servers that log to stderr do. The same warning is recorded on anomalyco/opencode issue #58173.
Why it happens
pipe() adds a drain listener for back-pressure. After the child is killed that listener is left behind, so later stdio sessions accumulate past the default max of 10.
Affected versions
TypeScript SDK stdio client. The linked issue does not name a package version. Reproduced from a client that starts local stdio servers; issue #780 reports the same leftover listeners from a JSON parse error after close.
Fix steps
0 of 2 done
Your check marks stay in this browser only.
How to check it worked
- After opening and closing several local stdio servers that write to stderr, Node no longer prints
MaxListenersExceededWarningfordrainlisteners onWriteStream.
If it still fails
- Raising
setMaxListenersonly hides the warning. The listeners still accumulate. - The linked issue does not give a one-off command that clears already-attached
drainlisteners besides restarting the Node process.
Sources and credit
Summarized in our own words from these public reports. Credit goes to their authors.
Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change
Hit an error we don't cover? Submit it