Problem
When Qwen Code restarts or reinitializes MCP servers, a race condition occurs that creates duplicate MCP processes instead of replacing them.
Root Cause Analysis
In McpClientManager.discoverMcpToolsForServer():
async discoverMcpToolsForServer(serverName, cliConfig) {
const existingClient = this.clients.get(serverName);
if (existingClient) {
await existingClient.disconnect();
this.clients.delete(serverName);
}
const client = new McpClient(...);
this.clients.set(serverName, client);
await client.connect();
}
Race condition window: Between disconnect() and connect(), the old MCP process is still running.
Evidence
kotolizator (PID 30400) → ACP (30452) → 2 MCP processes (30477, 30513) created 21 seconds apart
Environment
Qwen Code v0.15.6, Node.js v22.22.1, Linux
Problem
When Qwen Code restarts or reinitializes MCP servers, a race condition occurs that creates duplicate MCP processes instead of replacing them.
Root Cause Analysis
In
McpClientManager.discoverMcpToolsForServer():Race condition window: Between
disconnect()andconnect(), the old MCP process is still running.Evidence
kotolizator (PID 30400) → ACP (30452) → 2 MCP processes (30477, 30513) created 21 seconds apart
Environment
Qwen Code v0.15.6, Node.js v22.22.1, Linux