fix(ngcc): ensure lockfile is removed when analyzeFn fails (#37739)
Previously an error thrown in the `analyzeFn` would cause the ngcc process to exit immediately without removing the lockfile, and potentially before the unlocker process had been successfully spawned resulting in the lockfile being orphaned and left behind. Now we catch these errors and remove the lockfile as needed. PR Close #37739
This commit is contained in:

committed by
Andrew Kushnir

parent
df2cd37ed2
commit
1a1f99af37
@ -28,13 +28,13 @@ export class ClusterExecutor implements Executor {
|
||||
|
||||
async execute(analyzeEntryPoints: AnalyzeEntryPointsFn, _createCompileFn: CreateCompileFn):
|
||||
Promise<void> {
|
||||
return this.lockFile.lock(() => {
|
||||
return this.lockFile.lock(async () => {
|
||||
this.logger.debug(
|
||||
`Running ngcc on ${this.constructor.name} (using ${this.workerCount} worker processes).`);
|
||||
const master = new ClusterMaster(
|
||||
this.workerCount, this.fileSystem, this.logger, this.fileWriter, this.pkgJsonUpdater,
|
||||
analyzeEntryPoints, this.createTaskCompletedCallback);
|
||||
return master.run();
|
||||
return await master.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,11 @@ export class AsyncLocker {
|
||||
*/
|
||||
async lock<T>(fn: () => Promise<T>): Promise<T> {
|
||||
await this.create();
|
||||
return fn().finally(() => this.lockFile.remove());
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
this.lockFile.remove();
|
||||
}
|
||||
}
|
||||
|
||||
protected async create() {
|
||||
|
Reference in New Issue
Block a user