Skip to content

process: return unregister fn from finalization - #66482

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:process-finalization-unregister-fn
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:process-finalization-unregister-fn

Conversation

@mcollina

@mcollina mcollina commented Oct 3, 2026

Copy link
Copy Markdown
Member

process.finalization.register() and process.finalization.registerBeforeExit() now return a function that removes that specific registration:

const unregister = process.finalization.register(obj, onExit);
// later
unregister();

Other registrations for the same object are left in place, calling the function more than once is a no-op, and the function does not hold a strong reference to obj.

Each registration now uses its WeakRef as the FinalizationRegistry unregister token. This also fixes process.finalization.unregister(obj), which called registry.unregister(obj) although obj was never passed as a token, so the registry entries were never removed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01P3R4Ecvt8z8p4FHGb3wu9Y

process.finalization.register() and registerBeforeExit() now return
a function that removes only that registration, leaving other
registrations for the same object in place. The function does not
hold a strong reference to the object.

Each registration now uses its WeakRef as the unregister token, which
also makes process.finalization.unregister() remove the entries from
the FinalizationRegistry; previously it passed the object as the
token, which was never registered, so the call had no effect.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. labels Oct 3, 2026
@mcollina
mcollina force-pushed the process-finalization-unregister-fn branch from cbf147f to e214630 Compare October 3, 2026 14:33
@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.43%. Comparing base (8bf7793) to head (e214630).
⚠️ Report is 121 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66482      +/-   ##
==========================================
+ Coverage   90.39%   90.43%   +0.03%     
==========================================
  Files         792      790       -2     
  Lines      275580   275448     -132     
  Branches    52840    52833       -7     
==========================================
- Hits       249104   249091      -13     
+ Misses      16897    16765     -132     
- Partials     9579     9592      +13     
Files with missing lines Coverage Δ
lib/internal/process/finalization.js 100.00% <100.00%> (ø)

... and 69 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 6, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 6, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants