Skip to content

Commit 7ffbbac

Browse files
committed
fix(@angular/build): ensure application builder cleanly exits on thrown post-bundle errors
When an unhandled exception is thrown during post-bundle steps (such as IndexHtmlGenerator.readIndex throwing when an index HTML file is missing or unreadable), executeBuild() previously re-threw without calling .dispose() on executionResult or angularCompilationContext. Consequently, open ESBuild child processes, TypeScript compiler worker threads, and SQLite database connections prevented the Node.js process from exiting. This commit addresses the issue by: 1. Wrapping the entire body of executeBuild() in a try...catch block and instantiating executionResult immediately after bundlerContexts is created, so any thrown error reliably disposes all worker pools and AST caches before re-throwing. 2. Closing the SQLite cache store (angular-i18n.db) in I18nInliner.close() alongside worker pool destruction. 3. Ensuring Sass workers are shut down in build-action even if an initial --watch build throws an exception. Closes #33716
1 parent 902e8ea commit 7ffbbac

4 files changed

Lines changed: 218 additions & 209 deletions

File tree

packages/angular/build/src/builders/application/build-action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ export async function* runEsBuildBuildAction(
8181
const withProgress: typeof withSpinner = progress ? withSpinner : withNoProgress;
8282

8383
// Initial build
84-
let result: ExecutionResult;
84+
let result: ExecutionResult | undefined;
8585
try {
8686
// Perform the build action
8787
result = await withProgress('Building...', () => action());
8888

8989
// Log all diagnostic (error/warning/logs) messages
9090
await logMessages(logger, result, colors, jsonLogs);
9191
} finally {
92-
// Ensure Sass workers are shutdown if not watching
93-
if (!watch) {
92+
// Ensure Sass workers are shutdown if not watching or if the initial build failed
93+
if (!watch || !result) {
9494
shutdownSassWorkerPool();
9595
}
9696
}

0 commit comments

Comments
 (0)