Skip to content

Commit b67ce5e

Browse files
Remove process error listener in cleanupListeners
1 parent 064cd99 commit b67ce5e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/client/src/client/stdio.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class StdioClientTransport implements Transport {
9797
private _stderrStream: PassThrough | null = null;
9898
private _onServerDataHandler?: (chunk: Buffer) => void;
9999
private _onServerErrorHandler?: (error: Error) => void;
100+
private _onProcessErrorHandler?: (error: Error) => void;
100101

101102
onclose?: () => void;
102103
onerror?: (error: Error) => void;
@@ -144,10 +145,11 @@ export class StdioClientTransport implements Transport {
144145
this._process.stdout?.on('error', this._onServerErrorHandler);
145146
this._process.stdin?.on('error', this._onServerErrorHandler);
146147

147-
this._process.on('error', error => {
148+
this._onProcessErrorHandler = error => {
148149
reject(error);
149150
this.onerror?.(error);
150-
});
151+
};
152+
this._process.on('error', this._onProcessErrorHandler);
151153
this._process.once('spawn', () => resolve());
152154
this._process.once('close', _code => {
153155
if (this._process) {
@@ -210,6 +212,9 @@ export class StdioClientTransport implements Transport {
210212
process.stdout?.off('error', this._onServerErrorHandler);
211213
process.stdin?.off('error', this._onServerErrorHandler);
212214
}
215+
if (this._onProcessErrorHandler) {
216+
process.off('error', this._onProcessErrorHandler);
217+
}
213218
}
214219

215220
async close(): Promise<void> {

packages/client/test/client/crossSpawn.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ describe('StdioClientTransport using cross-spawn', () => {
200200
expect(stdout.listenerCount('data')).toBe(1);
201201
expect(stdout.listenerCount('error')).toBe(1);
202202
expect(stdin.listenerCount('error')).toBe(1);
203+
expect(proc.listenerCount('error')).toBe(1);
203204

204205
const closed = transport.close();
205206
proc.exitCode = 0;
@@ -209,6 +210,7 @@ describe('StdioClientTransport using cross-spawn', () => {
209210
expect(stdout.listenerCount('data')).toBe(0);
210211
expect(stdout.listenerCount('error')).toBe(0);
211212
expect(stdin.listenerCount('error')).toBe(0);
213+
expect(proc.listenerCount('error')).toBe(0);
212214
});
213215

214216
describe('windowsHide', () => {

0 commit comments

Comments
 (0)