Skip to content

Commit be2e207

Browse files
cklinCopilot
andcommitted
Handle CLI server stdin EPIPE on teardown
The CLI server process's stdin can emit an asynchronous 'error' during teardown: killProcessIfRunning() writes a "shutdown" request and then immediately end()s and kill()s the process, so on Windows the buffered write can complete with EPIPE once the read end closes. With no listener this became an unhandled error that faulted whichever operation was running, causing the flaky "should restart the database and run a query" failures in the Windows cli-integration tests (the restart command also restarts the CLI server via cliServer.restartCliServer()). Attach an 'error' listener to the CLI server's stdin once per process in launchProcess(). The command outcome is still reported via stdout / process close, so a genuine failure is not masked; only the redundant async stream error is handled (and logged). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 90105d62-02ab-405e-9c95-10466c971814
1 parent 3c16a18 commit be2e207

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • extensions/ql-vscode/src/codeql-cli

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export class CodeQLCliServer implements Disposable {
382382
]
383383
: [];
384384

385-
return spawnServer(
385+
const child = spawnServer(
386386
codeQlPath,
387387
"CodeQL CLI Server",
388388
["execute", "cli-server"],
@@ -392,6 +392,22 @@ export class CodeQLCliServer implements Disposable {
392392
/**/
393393
},
394394
);
395+
396+
// The CLI server's stdin can emit an asynchronous 'error' when the process
397+
// is torn down. In particular, killProcessIfRunning() writes a "shutdown"
398+
// request and then immediately end()s and kill()s the process, so on
399+
// Windows the buffered write can fail with EPIPE once the read end closes.
400+
// Without a handler this surfaces as an unhandled error that faults an
401+
// unrelated in-progress operation. Handle it here (once per process, so no
402+
// listener accumulates) since the command outcome is reported separately
403+
// via stdout / process close.
404+
child.stdin.on("error", (e) => {
405+
void this.logger.log(
406+
`CodeQL CLI Server stdin error (ignored): ${getErrorMessage(e)}`,
407+
);
408+
});
409+
410+
return child;
395411
}
396412

397413
private async runCodeQlCliInternal(

0 commit comments

Comments
 (0)