Skip to content

fix(@angular/build): prevent esbuild service child process leakage#33267

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix/prevent-esbuild-leak
Open

fix(@angular/build): prevent esbuild service child process leakage#33267
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix/prevent-esbuild-leak

Conversation

@clydin
Copy link
Copy Markdown
Member

@clydin clydin commented May 28, 2026

Use scoped esbuild.context() for single builds to guarantee accurate tracking and clean disposal of all internal esbuild service child processes. Additionally, wrap runEsBuildBuildAction in a try/finally block to deterministically trigger context disposal when a single build finishes or encounters an error.

This leakage primarily impacts programmatic usage and custom Architect decorators, where the hosting Node.js process remains alive after build completion.

Fixes #33201

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request wraps the watcher setup and initial build result emission in a try-finally block to ensure that the build result is disposed of when not in watch mode. It also simplifies the bundler context by always creating and rebuilding an esbuild context instead of branching for non-incremental builds. A review comment identifies a potential resource leak if an error occurs during the initial emit or watcher setup when watch mode is enabled, as the current finally block only disposes of the result if watch mode is disabled. A suggestion is provided to track whether the generator successfully transitions to the watch loop and clean up resources accordingly.

Comment thread packages/angular/build/src/builders/application/build-action.ts
Use scoped esbuild.context() for single builds to guarantee accurate tracking and clean disposal of all internal esbuild service child processes. Additionally, wrap runEsBuildBuildAction in a try/finally block leveraging a state tracking flag to deterministically trigger context disposal for all single builds and watch initialization failure paths.

This leakage primarily impacts programmatic usage and custom Architect decorators, where the hosting Node.js process remains alive after build completion.

Fixes angular#33201
@clydin clydin force-pushed the fix/prevent-esbuild-leak branch from 81d0675 to 2d9b166 Compare May 28, 2026 15:45
@clydin clydin added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels May 28, 2026
@clydin clydin requested a review from alan-agius4 May 28, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@angular/build: leaves esbuild service child alive after watch:false build

1 participant