fix(ngcc): give up re-spawing crashed worker process after 3 attempts (#36626)

Previously, when the last worker process crashed, the master process
would try to re-spawn it indefinitely. This could lead to an infinite
loop (if for some reason the worker process kept crashing).

This commit avoids this by limiting the number of re-spawn attempts to
3, after which ngcc will exit with an error.

PR Close #36626
This commit is contained in:
George Kalpakas 2020-04-29 21:28:26 +03:00 committed by Andrew Kushnir
parent 966598cda7
commit 793cb328de

View File

@ -32,6 +32,7 @@ export class ClusterMaster {
private taskAssignments = new Map<number, {task: Task, files?: AbsoluteFsPath[]}|null>();
private taskQueue: TaskQueue;
private onTaskCompleted: TaskCompletedCallback;
private remainingRespawnAttempts = 3;
constructor(
private maxWorkerCount: number, private fileSystem: FileSystem, private logger: Logger,
@ -184,10 +185,14 @@ export class ClusterMaster {
this.logger.debug(`Not spawning another worker process to replace #${
worker.id}. Continuing with ${spawnedWorkerCount} workers...`);
this.maybeDistributeWork();
} else {
} else if (this.remainingRespawnAttempts > 0) {
this.logger.debug(`Spawning another worker process to replace #${worker.id}...`);
this.remainingRespawnAttempts--;
cluster.fork();
} else {
throw new Error(
'All worker processes crashed and attempts to re-spawn them failed. ' +
'Please check your system and ensure there is enough memory available.');
}
}
}