@@ -168,6 +168,7 @@ export class UtilityProcess extends Disposable {
168
168
private process : ElectronUtilityProcess | undefined = undefined ;
169
169
private processPid : number | undefined = undefined ;
170
170
private configuration : IUtilityProcessConfiguration | undefined = undefined ;
171
+ private killed = false ;
171
172
172
173
constructor (
173
174
@ILogService private readonly logService : ILogService ,
@@ -314,18 +315,19 @@ export class UtilityProcess extends Disposable {
314
315
315
316
// Exit
316
317
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 ) ;
318
320
319
321
// Event
320
- this . _onExit . fire ( { pid : this . processPid ! , code, signal : 'unknown' } ) ;
322
+ this . _onExit . fire ( { pid : this . processPid ! , code : normalizedCode , signal : 'unknown' } ) ;
321
323
322
324
// Cleanup
323
325
this . onDidExitOrCrashOrKill ( ) ;
324
326
} ) ) ;
325
327
326
328
// Child process gone
327
329
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 ) ) {
329
331
this . log ( `crashed with code ${ details . exitCode } and reason '${ details . reason } '` , Severity . Error ) ;
330
332
331
333
// Telemetry
@@ -415,12 +417,24 @@ export class UtilityProcess extends Disposable {
415
417
const killed = this . process . kill ( ) ;
416
418
if ( killed ) {
417
419
this . log ( 'successfully killed the process' , Severity . Info ) ;
420
+ this . killed = true ;
418
421
this . onDidExitOrCrashOrKill ( ) ;
419
422
} else {
420
423
this . log ( 'unable to kill the process' , Severity . Warning ) ;
421
424
}
422
425
}
423
426
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
+
424
438
private onDidExitOrCrashOrKill ( ) : void {
425
439
if ( typeof this . processPid === 'number' ) {
426
440
UtilityProcess . all . delete ( this . processPid ) ;
0 commit comments