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 29 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
@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 added resume-ci-failed Resuming CI with the resume-ci label failed and requires manual intervention. and removed resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels 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

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. resume-ci-failed Resuming CI with the resume-ci label failed and requires manual intervention. 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.

4 participants