Skip to content

Commit 8a07747

Browse files
Pause stdin if we were the only listeners to the data events
1 parent 6ebf67e commit 8a07747

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/server/stdio.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ export class StdioServerTransport implements Transport {
6262
}
6363

6464
async close(): Promise<void> {
65-
// Remove our event listeners
65+
// Remove our event listeners first
6666
this._stdin.off("data", this._ondata);
6767
this._stdin.off("error", this._onerror);
68-
69-
// Destroy streams to ensure they're fully closed
70-
this._stdin.destroy();
71-
this._stdout.destroy();
68+
69+
// Check if we were the only data listener
70+
const remainingDataListeners = this._stdin.listenerCount('data');
71+
if (remainingDataListeners === 0) {
72+
// Only pause stdin if we were the only listener
73+
// This prevents interfering with other parts of the application that might be using stdin
74+
this._stdin.pause();
75+
}
7276

7377
// Clear the buffer and notify closure
7478
this._readBuffer.clear();

0 commit comments

Comments
 (0)