Commit Graph
8 Commits
Author SHA1 Message Date
Matteo Collina 9a9f7e87b8 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 <matteo.collina@gmail.com>
Assisted-by: pi
PR-URL: https://github.com/nodejs/node/pull/66482
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-10-18 06:36:43 +00:00
Tim Perry 89df046a21 test: keep finalization before-exit ref alive
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64521
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2026-07-17 16:39:25 +00:00
Trivikram Kamat 75aec8ecf8 process: fix finalization cleanup ref tracking
Use SafeSet collections for finalization refs so insertion, removal,
and emptiness checks match the identity-based tracking model.

This also fixes cleanup removal for collected refs. Previously cleanup
used the ref index as the splice delete count, which could remove later
live refs when the collected ref was not first.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: https://github.com/nodejs/node/pull/64087
Fixes: https://github.com/nodejs/node/issues/64086
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
2026-06-30 21:38:02 +00:00
Trivikram Kamat c612f3583c test: keep finalization close fixture ref alive
The close fixture expects the registered object to still be reachable
when the process emits exit. Keep a strong reference outside setup() so
the assertion does not depend on platform-specific GC timing.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: https://github.com/nodejs/node/pull/64085
Refs: https://github.com/nodejs/reliability/issues?q=%22test-process-finalization%22
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2026-06-25 06:22:46 +00:00
Antoine du Hamel a05b47fbad test: reduce flakiness of different-registry-per-thread
There was an assumption that the `WeakRef` would be kept alive but
it seems to not always be true on Windows. This commit makes sure
it's kept alive.

Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63244
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2026-05-12 10:09:13 +02:00
Antoine du Hamel 2cc4c81e10 Revert "test: reduce flakiness of different-registry-per-thread"
This reverts commit 130398ab05.

PR-URL: https://github.com/nodejs/node/pull/63244
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2026-05-12 10:09:12 +02:00
Antoine du Hamel 130398ab05 test: reduce flakiness of different-registry-per-thread
There was an assumption that the `WeakRef` would be kept alive but
it seems to not always be true on Windows. This commit makes sure
it's kept alive.

Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63209
Fixes: https://github.com/nodejs/node/issues/63056
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
2026-05-11 04:47:51 +00:00
Vinicius Lourenço 05bb4a716b process: port on-exit-leak-free to core
PR-URL: https://github.com/nodejs/node/pull/53239
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
2024-07-11 17:57:20 +00:00