Skip to content

Commit 0b20783

Browse files
authored
utility process - treat exit code 15 as expected when killed (microsoft#186540) (microsoft#210738)
1 parent e4af377 commit 0b20783

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/vs/platform/utilityProcess/electron-main/utilityProcess.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export class UtilityProcess extends Disposable {
168168
private process: ElectronUtilityProcess | undefined = undefined;
169169
private processPid: number | undefined = undefined;
170170
private configuration: IUtilityProcessConfiguration | undefined = undefined;
171+
private killed = false;
171172

172173
constructor(
173174
@ILogService private readonly logService: ILogService,
@@ -314,18 +315,19 @@ export class UtilityProcess extends Disposable {
314315

315316
// Exit
316317
this._register(Event.fromNodeEventEmitter<number>(process, 'exit')(code => {
317-
this.log(`received exit event with code ${code}`, Severity.Info);
318+
const normalizedCode = this.isNormalExit(code) ? 0 : code;
319+
this.log(`received exit event with code ${normalizedCode}`, Severity.Info);
318320

319321
// Event
320-
this._onExit.fire({ pid: this.processPid!, code, signal: 'unknown' });
322+
this._onExit.fire({ pid: this.processPid!, code: normalizedCode, signal: 'unknown' });
321323

322324
// Cleanup
323325
this.onDidExitOrCrashOrKill();
324326
}));
325327

326328
// Child process gone
327329
this._register(Event.fromNodeEventEmitter<{ details: Details }>(app, 'child-process-gone', (event, details) => ({ event, details }))(({ details }) => {
328-
if (details.type === 'Utility' && details.name === serviceName) {
330+
if (details.type === 'Utility' && details.name === serviceName && !this.isNormalExit(details.exitCode)) {
329331
this.log(`crashed with code ${details.exitCode} and reason '${details.reason}'`, Severity.Error);
330332

331333
// Telemetry
@@ -415,12 +417,24 @@ export class UtilityProcess extends Disposable {
415417
const killed = this.process.kill();
416418
if (killed) {
417419
this.log('successfully killed the process', Severity.Info);
420+
this.killed = true;
418421
this.onDidExitOrCrashOrKill();
419422
} else {
420423
this.log('unable to kill the process', Severity.Warning);
421424
}
422425
}
423426

427+
private isNormalExit(exitCode: number): boolean {
428+
if (exitCode === 0) {
429+
return true;
430+
}
431+
432+
// Treat an exit code of 15 (SIGTERM) as a normal exit
433+
// if we triggered the termination from process.kill()
434+
435+
return this.killed && exitCode === 15 /* SIGTERM */;
436+
}
437+
424438
private onDidExitOrCrashOrKill(): void {
425439
if (typeof this.processPid === 'number') {
426440
UtilityProcess.all.delete(this.processPid);

0 commit comments

Comments
 (0)