diff --git a/src/server/stdio.test.ts b/src/server/stdio.test.ts index d0414224..5de990f2 100644 --- a/src/server/stdio.test.ts +++ b/src/server/stdio.test.ts @@ -123,7 +123,7 @@ test("should properly clean up resources when closed", async () => { const transport = new StdioServerTransport(mockStdin, mockStdout); await transport.start(); - // Send a message to potentially create 'drain' listeners + // Send a message to potentially create listeners await transport.send({ jsonrpc: "2.0", method: "test", id: 1 }); // Close the transport diff --git a/src/server/stdio.ts b/src/server/stdio.ts index 4e44cc33..e3c78b21 100644 --- a/src/server/stdio.ts +++ b/src/server/stdio.ts @@ -62,15 +62,14 @@ export class StdioServerTransport implements Transport { } async close(): Promise { - // Remove all event listeners + // Remove our event listeners this._stdin.off("data", this._ondata); this._stdin.off("error", this._onerror); - this._stdout.removeAllListeners('drain'); - - // Destroy both streams + + // Destroy streams to ensure they're fully closed this._stdin.destroy(); this._stdout.destroy(); - + // Clear the buffer and notify closure this._readBuffer.clear(); this.onclose?.();