@@ -313,11 +313,26 @@ export class CodeQLCliServer implements Disposable {
313313
314314 killProcessIfRunning ( ) : void {
315315 if ( this . process ) {
316+ const proc = this . process ;
317+
318+ // The shutdown write below is buffered and, on Windows, can flush
319+ // asynchronously *after* we end()/kill() the process, closing the read
320+ // end and producing an EPIPE 'error' on stdin. Without a handler that
321+ // async error is unhandled and gets attributed to an unrelated
322+ // in-progress operation. Attach a handler scoped to this teardown so it
323+ // is swallowed here; the process is killed and dereferenced immediately
324+ // afterwards, so the listener is short-lived and does not accumulate.
325+ proc . stdin . on ( "error" , ( e ) => {
326+ void this . logger . log (
327+ `CodeQL CLI Server shutdown stdin error (ignored): ${ getErrorMessage ( e ) } ` ,
328+ ) ;
329+ } ) ;
330+
316331 // Tell the Java CLI server process to shut down.
317332 void this . logger . log ( "Sending shutdown request" ) ;
318333 try {
319- this . process . stdin . write ( JSON . stringify ( [ "shutdown" ] ) , "utf8" ) ;
320- this . process . stdin . write ( this . nullBuffer ) ;
334+ proc . stdin . write ( JSON . stringify ( [ "shutdown" ] ) , "utf8" ) ;
335+ proc . stdin . write ( this . nullBuffer ) ;
321336 void this . logger . log ( "Sent shutdown request" ) ;
322337 } catch ( e ) {
323338 // We are probably fine here, the process has already closed stdin.
@@ -328,10 +343,10 @@ export class CodeQLCliServer implements Disposable {
328343 }
329344 // Close the stdin and stdout streams.
330345 // This is important on Windows where the child process may not die cleanly.
331- this . process . stdin . end ( ) ;
332- this . process . kill ( ) ;
333- this . process . stdout . destroy ( ) ;
334- this . process . stderr . destroy ( ) ;
346+ proc . stdin . end ( ) ;
347+ proc . kill ( ) ;
348+ proc . stdout . destroy ( ) ;
349+ proc . stderr . destroy ( ) ;
335350 this . process = undefined ;
336351 }
337352 }
0 commit comments