Title: `process.finalization` removes extra refs during cleanup · Issue #64086 · nodejs/node · GitHub
Open Graph Title: `process.finalization` removes extra refs during cleanup · Issue #64086 · nodejs/node
X Title: `process.finalization` removes extra refs during cleanup · Issue #64086 · nodejs/node
Description: Version main Platform macOS 26.5.0 Subsystem process What steps will reproduce the bug? import process from 'node:process'; import { setImmediate } from 'node:timers/promises'; const kept = []; function onFinalize(ref) { console.log(`fin...
Open Graph Description: Version main Platform macOS 26.5.0 Subsystem process What steps will reproduce the bug? import process from 'node:process'; import { setImmediate } from 'node:timers/promises'; const kept = []; fun...
X Description: Version main Platform macOS 26.5.0 Subsystem process What steps will reproduce the bug? import process from 'node:process'; import { setImmediate } from 'node:timers/promises'; cons...
Opengraph URL: https://github.com/nodejs/node/issues/64086
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`process.finalization` removes extra refs during cleanup","articleBody":"### Version\n\nmain\n\n### Platform\n\n```text\nmacOS 26.5.0\n```\n\n### Subsystem\n\nprocess\n\n### What steps will reproduce the bug?\n\n```js\nimport process from 'node:process';\nimport { setImmediate } from 'node:timers/promises';\n\nconst kept = [];\n\nfunction onFinalize(ref) {\n console.log(`finalized: ${ref.name}`);\n}\n\nfunction setup() {\n const first = { name: 'first' };\n let collected = { name: 'collected' };\n const third = { name: 'third' };\n\n kept.push(first, third);\n\n process.finalization.register(first, onFinalize);\n process.finalization.register(collected, onFinalize);\n process.finalization.register(third, onFinalize);\n\n collected = null;\n}\n\nsetup();\n\n// Give V8 a few chances to collect `collected` and run the\n// FinalizationRegistry cleanup before process exit.\nfor (let i = 0; i \u003c 10; i++) {\n gc();\n await setImmediate();\n}\n\nconsole.log('expected: finalized: first');\nconsole.log('expected: finalized: third');\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\n```console\nexpected: finalized: first\nexpected: finalized: third\nfinalized: first\nfinalized: third\n```\n\nBoth `first` and `third` are strongly reachable through `kept`, so both should remain registered and run their finalization callbacks during process exit.\n\n### What do you see instead?\n\n```console\nexpected: finalized: first\nexpected: finalized: third\nfinalized: first\n```\n\nAfter `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.\n\n### Additional information\n\nNoticed while working on https://github.com/nodejs/node/pull/64085\n\nThe docs for [`process.finalization.register(ref, callback)`](https://nodejs.org/api/process.html#processfinalizationregisterref-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.\"","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-06-23T05:33:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/64086/node/issues/64086"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0436868f-1222-1e17-bf43-fe35122ce082 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E872:BB1BD:B0DDB2:F0C6FB:6A4D51D8 |
| html-safe-nonce | 6124da5d2cec9ef0e212be8488b0ac0ae9efbb2aa4dab3b8f96d1c34f6d61220 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODcyOkJCMUJEOkIwRERCMjpGMEM2RkI6NkE0RDUxRDgiLCJ2aXNpdG9yX2lkIjoiNjQwODg5MjExMTQ0MTk3MzcyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 013212a9a1306f0978720004c3ac592fcd75787db6efbd20dbc582f018bada5d |
| hovercard-subject-tag | issue:4722932457 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/64086/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20c134337f90defdeb3ed294c6f3f113f02cede68e3caaa2fd74c2cd686340ab/nodejs/node/issues/64086 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20c134337f90defdeb3ed294c6f3f113f02cede68e3caaa2fd74c2cd686340ab/nodejs/node/issues/64086 |
| og:image:alt | Version main Platform macOS 26.5.0 Subsystem process What steps will reproduce the bug? import process from 'node:process'; import { setImmediate } from 'node:timers/promises'; const kept = []; fun... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trivikr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fc8347865a14e2ec811533d68f929cf4e0ec19 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width