Skip to content

StdioClientTransport.close() doesn't terminate child processes, causing memory leaks #885

@nhtruong

Description

@nhtruong

The StdioClientTransport.close() method doesn't properly terminate spawned child processes, causing
memory leaks in applications that frequently connect/disconnect from STDIO MCP servers.

In client/stdio.js, the close() method only aborts the spawn signal and nullifies the process
reference, but doesn't actually kill the running child process:

async close() {
    this._abortController.abort();  // Only prevents new spawns
    this._process = undefined;      // Just removes reference
    this._readBuffer.clear();
}

To Reproduce

  FOR 1000 times:
      transport = new StdioClientTransport(server_command)
      client = new Client()

      client.connect(transport)  // spawns child process
      pid = transport.pid

      client.close()             // BUG: doesn't kill child process

      // Process with 'pid' is still running (memory leak)

  // Result: 1000 orphaned processes still running

Expected behavior
When close() is called, the spawned child process should be terminated to prevent resource leaks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions