Skip to content

Commit

Permalink
fix(ngcc): give up re-spawing crashed worker process after 3 attempts (
Browse files Browse the repository at this point in the history
…angular#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 angular#36626
  • Loading branch information
gkalpak authored and profanis committed Sep 5, 2020
1 parent 69d2990 commit b336d6c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/compiler-cli/ngcc/src/execution/cluster/master.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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.');
}
}
}
Expand Down

0 comments on commit b336d6c

Please sign in to comment.