Skip to content

Commit

Permalink
Handle exit and error events for query server child processes
Browse files Browse the repository at this point in the history
  • Loading branch information
angelapwen committed May 14, 2024
1 parent 247df2e commit 067a1c4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions extensions/ql-vscode/src/query-server/query-server-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,32 @@ export class QueryServerClient extends DisposableObject {
this.nextCallback = 0;
this.nextProgress = 0;
this.progressCallbacks = {};
child.on("close", () => {
this.restartQueryServerOnFailure();

// 'exit' may or may not fire after 'error' event, so we want to guard against restarting the
// query server twice if both events fire.
let wasExitOrErrorHandled = false;
child.on("error", (err: Error) => {
if (!wasExitOrErrorHandled) {
void this.logger.log(`Query server terminated with error: ${err}.`);
this.restartQueryServerOnFailure();
wasExitOrErrorHandled = true;
}
});
child.on("exit", (code: number, signal: string) => {
if (!wasExitOrErrorHandled) {
if (code !== null) {
void this.logger.log(
`Query server terminated with exit code: ${code}.`,
);
}
if (signal !== null) {
void this.logger.log(
`Query server terminated due to receipt of signal: ${signal}.`,
);
}
this.restartQueryServerOnFailure();
wasExitOrErrorHandled = true;
}
});
}

Expand Down

0 comments on commit 067a1c4

Please sign in to comment.