fix: process host early exit crash (#26642)

This commit is contained in:
Max Schmitt 2023-08-23 18:03:24 +02:00 committed by GitHub
parent d08b38013d
commit f41c862ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,7 +28,7 @@ export type ProcessExitData = {
}; };
export class ProcessHost extends EventEmitter { export class ProcessHost extends EventEmitter {
private process!: child_process.ChildProcess; private process: child_process.ChildProcess | undefined;
private _didSendStop = false; private _didSendStop = false;
private _didFail = false; private _didFail = false;
private didExit = false; private didExit = false;
@ -85,7 +85,7 @@ export class ProcessHost extends EventEmitter {
}); });
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
this.process.once('exit', (code, signal) => reject(new Error(`process exited with code "${code}" and signal "${signal}" before it became ready`))); this.process!.once('exit', (code, signal) => reject(new Error(`process exited with code "${code}" and signal "${signal}" before it became ready`)));
this.once('ready', () => resolve()); this.once('ready', () => resolve());
}); });
@ -154,6 +154,6 @@ export class ProcessHost extends EventEmitter {
private send(message: { method: string, params?: any }) { private send(message: { method: string, params?: any }) {
if (debug.enabled('pw:test:protocol')) if (debug.enabled('pw:test:protocol'))
debug('pw:test:protocol')('SEND ► ' + JSON.stringify(message)); debug('pw:test:protocol')('SEND ► ' + JSON.stringify(message));
this.process.send(message); this.process?.send(message);
} }
} }