From fd204481115fe32277beb86ccc726976deb61f79 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 21 Oct 2026 21:26:20 -0700 Subject: [PATCH] test: keep objects alive in finalization fixtures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process.finalization only holds weak references to registered objects. In unregister-function.mjs and finalization-cleanup.mjs the registered objects were not captured by any closure, so a GC before exit could collect them, skipping their exit callbacks and failing the assertions. Reference them from the exit listeners so they stay reachable. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011DQrzezHzwzfCYeh2cYm2U Signed-off-by: Matteo Collina PR-URL: https://github.com/nodejs/node/pull/66869 Reviewed-By: Gürgün Dayıoğlu Reviewed-By: Luigi Pinca --- test/fixtures/process/finalization-cleanup.mjs | 2 ++ test/fixtures/process/unregister-function.mjs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/test/fixtures/process/finalization-cleanup.mjs b/test/fixtures/process/finalization-cleanup.mjs index 88d6c17cc7e..8b7705b64d6 100644 --- a/test/fixtures/process/finalization-cleanup.mjs +++ b/test/fixtures/process/finalization-cleanup.mjs @@ -30,5 +30,7 @@ for (let i = 0; i < 10; i++) { } process.on('exit', function () { + // Keep `first` and `third` alive until exit; registrations only hold them weakly. + deepStrictEqual(keptAlive.map((obj) => obj.name), ['first', 'third']) deepStrictEqual(finalized, ['first', 'third']) }) diff --git a/test/fixtures/process/unregister-function.mjs b/test/fixtures/process/unregister-function.mjs index b74a5b8203a..01f704e4fa1 100644 --- a/test/fixtures/process/unregister-function.mjs +++ b/test/fixtures/process/unregister-function.mjs @@ -25,5 +25,8 @@ unregisterABeforeExit() unregisterBAgain() process.on('exit', function () { + // Keep `a` and `b` alive until exit; registrations only hold them weakly. + strictEqual(a.name, 'a') + strictEqual(b.name, 'b') strictEqual(calls.join(','), 'b:exit') })