You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
process.finalization removes extra refs during cleanup #64086
importprocessfrom'node:process';import{setImmediate}from'node:timers/promises';constkept=[];functiononFinalize(ref){console.log(`finalized: ${ref.name}`);}functionsetup(){constfirst={name: 'first'};letcollected={name: 'collected'};constthird={name: 'third'};kept.push(first,third);process.finalization.register(first,onFinalize);process.finalization.register(collected,onFinalize);process.finalization.register(third,onFinalize);collected=null;}setup();// Give V8 a few chances to collect `collected` and run the// FinalizationRegistry cleanup before process exit.for(leti=0;i<10;i++){gc();awaitsetImmediate();}console.log('expected: finalized: first');console.log('expected: finalized: third');
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
expected: finalized: firstexpected: finalized: thirdfinalized: firstfinalized: third
Both first and third are strongly reachable through kept, so both should remain registered and run their finalization callbacks during process exit.
What do you see instead?
expected: finalized: firstexpected: finalized: thirdfinalized: first
After collected is garbage-collected, cleanup removes its ref and also removes third because splice(1, 2) deletes two entries. As a result, third is still alive but its exit callback is skipped.
The docs for process.finalization.register(ref, callback) say that it "registers a callback to be called when the process emits the exit event if the ref object was not garbage collected."
Activity
process: fix finalization cleanup ref tracking
process: fix finalization cleanup ref tracking
process: fix finalization cleanup ref tracking
process: fix finalization cleanup ref tracking
process: fix finalization cleanup ref tracking
process: fix finalization cleanup ref tracking