Skip to content

Commit 2babb0b

Browse files
authored
Handle exit and error events for query server child processes (#3610)
1 parent 247df2e commit 2babb0b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

extensions/ql-vscode/src/query-server/query-server-client.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,32 @@ export class QueryServerClient extends DisposableObject {
240240
this.nextCallback = 0;
241241
this.nextProgress = 0;
242242
this.progressCallbacks = {};
243-
child.on("close", () => {
244-
this.restartQueryServerOnFailure();
243+
244+
// 'exit' may or may not fire after 'error' event, so we want to guard against restarting the
245+
// query server twice if both events fire.
246+
let wasExitOrErrorHandled = false;
247+
child.on("error", (err: Error) => {
248+
if (!wasExitOrErrorHandled) {
249+
void this.logger.log(`Query server terminated with error: ${err}.`);
250+
this.restartQueryServerOnFailure();
251+
wasExitOrErrorHandled = true;
252+
}
253+
});
254+
child.on("exit", (code: number, signal: string) => {
255+
if (!wasExitOrErrorHandled) {
256+
if (code !== null) {
257+
void this.logger.log(
258+
`Query server terminated with exit code: ${code}.`,
259+
);
260+
}
261+
if (signal !== null) {
262+
void this.logger.log(
263+
`Query server terminated due to receipt of signal: ${signal}.`,
264+
);
265+
}
266+
this.restartQueryServerOnFailure();
267+
wasExitOrErrorHandled = true;
268+
}
245269
});
246270
}
247271

0 commit comments

Comments
 (0)