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.


AI generated. Reviewed by me.

@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.47%. Comparing base (cbac135) to head (4a67914).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66482   +/-   ##
=======================================
  Coverage   90.47%   90.47%           
=======================================
  Files         791      791           
  Lines      277088   277101   +13     
  Branches    53276    53276           
=======================================
+ Hits       250686   250707   +21     
+ Misses      16813    16802   -11     
- Partials     9589     9592    +3     
Files with missing lines Coverage Δ
lib/internal/process/finalization.js 100.00% <100.00%> (ø)

... and 24 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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina mcollina added the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 10, 2026
@nodejs-github-bot nodejs-github-bot added lacks-second-approval Commit Queue PRs awaiting a second collaborator approval or completion of the required wait. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. lacks-second-approval Commit Queue PRs awaiting a second collaborator approval or completion of the required wait. labels Oct 10, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

   ✖  This PR needs to wait 5 more hours to land (or 0 minutes if there is one more approval)
   ⚠  This PR has conflicts that must be resolved

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/66482
�[36m⠋�[39m Loading data for nodejs/node/pull/66482
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/66482
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66482
�[36m⠋�[39m Getting comments from nodejs/node/pull/66482
�[36m⠋�[39m Getting commits from nodejs/node/pull/66482
✔  Done loading data for nodejs/node/pull/66482
----------------------------------- PR info ------------------------------------
Title      process: return unregister fn from finalization (#66482)
Author     Matteo Collina <matteo.collina@gmail.com> (@mcollina)
Branch     mcollina:process-finalization-unregister-fn -> nodejs:main
Labels     process, needs-ci, commit-queue, lacks-second-approval
Commits    1
 - process: return unregister fn from finalization
Committers 1
 - Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66482
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/66482
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 03 Oct 2026 14:33:02 GMT
   ✔  Approvals: 1
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/66482#pullrequestreview-5420245948
   ✖  This PR needs to wait 5 more hours to land (or 0 minutes if there is one more approval)
   ⚠  This PR has conflicts that must be resolved
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-10-09T15:16:09Z: https://ci.nodejs.org/job/node-test-pull-request/78271/
�[36m⠙�[39m Querying data for job/node-test-pull-request/78271/
�[36m⠙�[39m Querying data for job/node-test-pull-request/78271/
�[36m⠙�[39m Querying API for job/node-test-pull-request/78271/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

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>
@mcollina mcollina added commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Oct 11, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Oct 11, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

⚠ This PR has conflicts that must be resolved

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/66482
�[36m⠋�[39m Loading data for nodejs/node/pull/66482
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/66482
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66482
�[36m⠋�[39m Getting comments from nodejs/node/pull/66482
�[36m⠋�[39m Getting commits from nodejs/node/pull/66482
✔  Done loading data for nodejs/node/pull/66482
----------------------------------- PR info ------------------------------------
Title      process: return unregister fn from finalization (#66482)
Author     Matteo Collina <matteo.collina@gmail.com> (@mcollina)
Branch     mcollina:process-finalization-unregister-fn -> nodejs:main
Labels     process, needs-ci, commit-queue
Commits    1
 - process: return unregister fn from finalization
Committers 1
 - Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66482
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/66482
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 03 Oct 2026 14:33:02 GMT
   ✔  Approvals: 1
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/66482#pullrequestreview-5420245948
   ⚠  This PR has conflicts that must be resolved
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-10-10T10:21:45Z: https://ci.nodejs.org/job/node-test-pull-request/78271/
�[36m⠙�[39m Querying data for job/node-test-pull-request/78271/
�[36m⠙�[39m Querying data for job/node-test-pull-request/78271/
�[36m⠙�[39m Querying API for job/node-test-pull-request/78271/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
�[36m⠹�[39m Querying API for job/node-test-pull-request/78271/
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

@mcollina
mcollina force-pushed the process-finalization-unregister-fn branch from e214630 to 4a67914 Compare October 12, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. 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.

4 participants