From 186373300ab37e19c36f9c37483fab30b3af375a Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 29 Apr 2020 21:28:26 +0300 Subject: [PATCH] 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 --- packages/compiler-cli/ngcc/src/execution/cluster/master.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/ngcc/src/execution/cluster/master.ts b/packages/compiler-cli/ngcc/src/execution/cluster/master.ts index c4831b6cf8..a29997b4f8 100644 --- a/packages/compiler-cli/ngcc/src/execution/cluster/master.ts +++ b/packages/compiler-cli/ngcc/src/execution/cluster/master.ts @@ -32,6 +32,7 @@ export class ClusterMaster { private taskAssignments = new Map(); 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.'); } } }