From 9912e542560fef86a2de308b5cc0252b6d16a67d Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 16 Oct 2026 08:40:00 +0000 Subject: [PATCH] process: return unregister fn from finalization 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: https://github.com/nodejs/node/pull/66482 Signed-off-by: Matteo Collina Assisted-by: pi --- doc/api/process.md | 19 ++++++++++++ lib/internal/process/finalization.js | 23 +++++++++++---- test/fixtures/process/unregister-function.mjs | 29 +++++++++++++++++++ test/parallel/test-process-finalization.mjs | 1 + 4 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/process/unregister-function.mjs diff --git a/doc/api/process.md b/doc/api/process.md index 38bcf8786807..36e087b2cd0a 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -2063,6 +2063,9 @@ Since it's not possible to build Node.js without libuv, this value is always `tr