From 8a077474a6f0e87fe3cba0e5ea820db06954d72c Mon Sep 17 00:00:00 2001 From: Jerome Date: Fri, 3 Jan 2025 19:05:38 +0000 Subject: [PATCH] Pause stdin if we were the only listeners to the data events --- src/server/stdio.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/server/stdio.ts b/src/server/stdio.ts index e3c78b21..30c80012 100644 --- a/src/server/stdio.ts +++ b/src/server/stdio.ts @@ -62,13 +62,17 @@ export class StdioServerTransport implements Transport { } async close(): Promise { - // Remove our event listeners + // Remove our event listeners first this._stdin.off("data", this._ondata); this._stdin.off("error", this._onerror); - - // Destroy streams to ensure they're fully closed - this._stdin.destroy(); - this._stdout.destroy(); + + // Check if we were the only data listener + const remainingDataListeners = this._stdin.listenerCount('data'); + if (remainingDataListeners === 0) { + // Only pause stdin if we were the only listener + // This prevents interfering with other parts of the application that might be using stdin + this._stdin.pause(); + } // Clear the buffer and notify closure this._readBuffer.clear();