Skip to content

test: keep objects alive in finalization fixtures - #66869

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-flaky-unregister-function
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-flaky-unregister-function

Conversation

@mcollina

@mcollina mcollina commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

test-process-finalization flakes on Windows CI in the unregister-function.mjs case:

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

'' !== 'b:exit'

process.finalization holds registered objects only through weak references, and skips the callback at exit if the object is gone. In the fixture, a and b are top-level bindings that no closure captures, so a GC before exit can collect b. Its exit callback then never runs. The same could hide a broken unregister of a.

finalization-cleanup.mjs has the same problem: first and third are only held by keptAlive, which nothing captures. Forcing a GC in beforeExit (--require a preload doing process.once('beforeExit', () => gc())) makes it fail deterministically with actual: []; with this change it passes.

Both fixtures now reference the objects from their exit listener so they stay reachable until the assertions run. The other fixtures already keep their objects alive this way, or expect them to be collected.

🤖 Generated with Claude Code

https://claude.ai/code/session_011DQrzezHzwzfCYeh2cYm2U

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure. labels Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (2052d0d) to head (3aa30fc).
⚠️ Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66869      +/-   ##
==========================================
- Coverage   90.50%   90.50%   -0.01%     
==========================================
  Files         797      797              
  Lines      278195   278221      +26     
  Branches    53453    53461       +8     
==========================================
+ Hits       251777   251800      +23     
- Misses      16795    16802       +7     
+ Partials     9623     9619       -4     

see 36 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.

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DQrzezHzwzfCYeh2cYm2U
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina changed the title test: keep objects alive in finalization fixture test: keep objects alive in finalization fixtures Oct 20, 2026
@mcollina
mcollina force-pushed the fix-flaky-unregister-function branch from 0c42211 to 3aa30fc Compare October 20, 2026 11:47

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@gurgunday gurgunday added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. author ready PRs with CI started, the required approvals, and no outstanding review comments. labels Oct 20, 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 20, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants