@@ -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 > {
0 commit comments