Skip to content

process: return unregister fn from finalization - #66482

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:process-finalization-unregister-fn
Oct 18, 2026
Merged

nodejs-github-bot merged 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.49%. Comparing base (77609be) to head (9912e54).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66482      +/-   ##
==========================================
- Coverage   92.85%   90.49%   -2.36%     
==========================================
  Files         428      797     +369     
  Lines      194693   277665   +82972     
  Branches    30091    53346   +23255     
==========================================
+ Hits       180774   251270   +70496     
- Misses      13593    16795    +3202     
- Partials      326     9600    +9274     
Files with missing lines Coverage Δ
lib/internal/process/finalization.js 100.00% <100.00%> (ø)

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

@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
@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 13, 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 13, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina mcollina added resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. semver-minor PRs that contain new features and should be released in the next minor version. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Oct 14, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Oct 14, 2026
@github-actions github-actions Bot added the resume-ci-failed Resuming CI with the resume-ci label failed and requires manual intervention. label Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Failed to resume CI

   ✖  test/parallel/test-process-finalization.mjs
   ℹ  https://ci.nodejs.org/job/node-test-binary-windows-js-suites/RUN_SUBSET=2,nodes=win11-vs2022-arm64-COMPILED_BY-vs2022_clang-arm64/43879/consoleText
✖  Refusing to resume CI: failures reference files changed by this PR
Full Auto Start CI output
�[36m⠋�[39m Validating Jenkins credentials
�[36m⠋�[39m Validating Jenkins credentials
✔  Jenkins credentials valid
�[36m⠙�[39m Looking for CI runs for pull request 66482
�[36m⠙�[39m Looking for CI runs for pull request 66482
�[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
✔  Found PR CI job 78353
�[36m⠹�[39m Querying data for job/node-test-pull-request/78353/
�[36m⠹�[39m Querying data for job/node-test-pull-request/78353/
�[36m⠹�[39m Querying API for job/node-test-pull-request/78353/
✔  Build data downloaded
�[36m⠹�[39m Checking whether PR CI job 78353 can be resumed
�[36m⠹�[39m Checking whether PR CI job 78353 can be resumed
✔  Jenkins offers a Resume build action
�[36m⠸�[39m Checking failures against changed PR files
�[36m⠸�[39m Checking failures against changed PR files
�[36m⠼�[39m Querying data for job/node-test-pull-request/78353/
�[36m⠼�[39m Querying API for job/node-test-pull-request/78353/
✔  Build data downloaded
�[36m⠴�[39m Querying failures of job/node-test-commit/93223/
�[36m⠴�[39m Querying failures of job/node-test-commit/93223/
�[36m⠴�[39m Querying API for job/node-test-commit-windows-fanned/81155/
�[36m⠴�[39m Querying API for job/node-test-binary-windows-js-suites/43879/
�[36m⠦�[39m Querying API for job/node-test-binary-windows-js-suites/RUN_SUBSET=1,nodes=win2016-COMPILED_BY-vs2022-x86/43865/
�[36m⠦�[39m Querying API for job/node-test-binary-windows-js-suites/RUN_SUBSET=2,nodes=win11-vs2022-arm64-COMPILED_BY-vs2022_clang-arm64/43879/
�[36m⠧�[39m Querying console text for job/node-test-binary-windows-js-suites/RUN_SUBSET=2,nodes=win11-vs2022-arm64-COMPILED_BY-vs2022_clang-arm64/43879/
✔  Data downloaded
   ✖  test/parallel/test-process-finalization.mjs
   ℹ  https://ci.nodejs.org/job/node-test-binary-windows-js-suites/RUN_SUBSET=2,nodes=win11-vs2022-arm64-COMPILED_BY-vs2022_clang-arm64/43879/consoleText
not ok 909 parallel/test-process-finalization
  ---
  duration_ms: 2388.99700
  severity: fail
  exitcode: 1
  stack: |-
    Test failure: 'should exit file unregister-function.mjs with code=0'
    Location: test\parallel\test-process-finalization.mjs:20:3
    Error: - process terminated with status 1, expected 0
        at TestContext.<anonymous> (file:///d:/workspace/node-test-binary-windows-js-suites/node/test/parallel/test-process-finalization.mjs:21:5)
        at Test.runInAsyncScope (node:async_hooks:227:14)
        at Test.run (node:internal/test_runner/test:1402:25)
        at Test.processPendingSubtests (node:internal/test_runner/test:974:18)
        at Test.postRun (node:internal/test_runner/test:1542:19)
        at Test.run (node:internal/test_runner/test:1467:12)
        at async Test.processPendingSubtests (node:internal/test_runner/test:974:7) {
      options: {
        cwd: 'd:\\workspace\\node-test-binary-windows-js-suites\\node\\test\\fixtures\\process'
      },
      command: 'd:\\workspace\\node-test-binary-windows-js-suites\\node\\Release\\node.exe --expose-gc unregister-function.mjs'
    }
    
    [process 12116]: --- stderr ---
    node:internal/assert/utils:146
      throw error;
      ^
    
    AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
    
    '' !== 'b:exit'
    
        at process.<anonymous> (file:///d:/workspace/node-test-binary-windows-js-suites/node/test/fixtures/process/unregister-function.mjs:28:3)
        at process.emit (node:events:514:20) {
      generatedMessage: true,
      code: 'ERR_ASSERTION',
      actual: '',
      expected: 'b:exit',
      operator: 'strictEqual',
      diff: 'simple'
    }
    
    Node.js v27.0.0-pre
    
    [process 12116]: --- stdout ---
    
    [process 12116]: status = 1, signal = null
  ...
✖  Refusing to resume CI: failures reference files changed by this PR

View workflow run

@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 15, 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 15, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

mcollina added a commit to mcollina/node that referenced this pull request Oct 16, 2026
The `changes` lists for `process.finalization.register()` and
`process.finalization.registerBeforeExit()` must be ordered newest first.
PR nodejs#66436 (marking these APIs as release candidate) has already landed in
`main` at v26.12.0, so the new nodejs#66482 (REPLACEME) entry must come before
it. Leaving both as REPLACEME makes the merged file out of order and fails
the `lint-md` check.

Refs: nodejs#66482

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Assisted-by: pi
mcollina added a commit to mcollina/node that referenced this pull request Oct 16, 2026
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.

Refs: nodejs#66482

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Assisted-by: pi
@mcollina
mcollina force-pushed the process-finalization-unregister-fn branch from 5fe4f07 to 30dcffb Compare October 16, 2026 08:41
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.

Refs: nodejs#66482

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Assisted-by: pi
@mcollina
mcollina force-pushed the process-finalization-unregister-fn branch from 30dcffb to 9912e54 Compare October 16, 2026 14:06
@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 17, 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 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina mcollina added commit-queue PRs queued for automated landing through the Commit Queue. and removed resume-ci-failed Resuming CI with the resume-ci label failed and requires manual intervention. labels Oct 18, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 9a9f7e8 into nodejs:main Oct 18, 2026
77 of 79 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 9a9f7e8

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 18, 2026
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. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants