Repository navigation
fix(cli): destroy the worker pool after the initial compilation - #142
Conversation
swcDir() created a Piscina pool for the initial compilation and never destroyed it. Long-lived processes that call swcDir() repeatedly, such as the @nestjs/cli swc builder in watch mode, leaked idle worker threads on each call. Destroy the pool in a finally block, so it is released on success and on failure. Closes #126 Co-authored-by: 你好怪凡 <9988024+higuaifan@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: e661703 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e6617030c4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
Problem
initialCompilation()inpackages/cli/src/swc/dir.tscreates a Piscina worker pool and does not destroy it. A one-shot CLI run exits, so the pool does not stay. But long-lived processes callswcDir()as a library. For example, the@nestjs/cliswc builder callsswcDir()on each file-add event in watch mode. Each call leaks a pool withminThreadsidle worker threads.Change
try/finallyand callawait workers.destroy()in thefinallyblock. The pool is released when the compilation succeeds and when it fails.try/finallyinstead ofPromise.prototype.finally. Thelibsetting inpackages/cli/tsconfig.jsondoes not declarePromise.prototype.finally. This was the review finding on fix(cli): Destroy the worker pool after the initial compilation #130.packages/cli/src/swc/__tests__/dir.test.ts. The test mockspiscinaand checks thatdestroy()is called once after a successful compilation and once after a failed compilation.@swc/cli.The watch path compiles with
dirWorkerdirectly and does not use this pool, so watch behavior does not change.This change is based on the investigation and the approach in #130 by the issue author.
Validation
All local checks below ran on commit e661703:
pnpm exec tsc --noEmitinpackages/cli: passed.pnpm exec jestinpackages/cli: 8 suites, 65 tests passed.dir.tschange, the 2 new tests indir.test.tsfailed.prettier --checkon the changed source and test files: passed.Closes #126
🤖 Generated with Claude Code