Skip to content

fix(cli): Destroy the worker pool after the initial compilation - #130

Open
你好怪凡 (higuaifan) wants to merge 1 commit into
swc-project:mainfrom
higuaifan:fix-swcdir-piscina-pool-leak
Open

你好怪凡 (higuaifan) wants to merge 1 commit into
swc-project:mainfrom
higuaifan:fix-swcdir-piscina-pool-leak

Conversation

@higuaifan

Copy link
Copy Markdown

Closes #126.

  1. initialCompilation() never destroys the Piscina pool it creates on the async path, so every swcDir() call permanently pins minThreads (= cores / 2) idle workers. Root cause, measurements and a nest-free repro are in the issue.
  2. Fix: .finally(() => workers.destroy()) on the pool's task chain. The watch path compiles via dirWorker directly and never touches this pool, so behavior is unchanged.
  3. Added src/swc/__tests__/dir.test.ts covering pool teardown after both a successful and a failed compilation. Both assertions fail without the fix.
  4. The .then() block is re-indented by the added chain link — the functional change is one line.

Investigated and engineered by Claude; I'm following up on this PR.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 35c843e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@swc/cli Patch

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

@CLAassistant

This comment was marked as outdated.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35c843e186

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

}
});
})
.finally(() => workers.destroy());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add Promise.finally to the package lib

This package's build script runs tsc, but packages/cli/tsconfig.json only includes ES2019.Array, ES2020.Promise, and ES2015 in lib; that combination declares Promise.allSettled but not Promise.prototype.finally. With this new call the package no longer type-checks (Property 'finally' does not exist on type 'Promise<...>'), so the CLI build will fail until the lib is updated or the cleanup is expressed without finally.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

@swc/cli: swcDir() leaks a Piscina worker pool per invocation when used as a library

2 participants