Title: ffi: refCallback()/unrefCallback() crash (SIGSEGV) when called on a garbage-collected callback · Issue #64880 · nodejs/node · GitHub
Open Graph Title: ffi: refCallback()/unrefCallback() crash (SIGSEGV) when called on a garbage-collected callback · Issue #64880 · nodejs/node
X Title: ffi: refCallback()/unrefCallback() crash (SIGSEGV) when called on a garbage-collected callback · Issue #64880 · nodejs/node
Description: Version main Platform N/A Subsystem ffi What steps will reproduce the bug? repro.c #include
Open Graph Description: Version main Platform N/A Subsystem ffi What steps will reproduce the bug? repro.c #include
X Description: Version main Platform N/A Subsystem ffi What steps will reproduce the bug? repro.c #include <stdint.h> int32_t noop(int32_t x) { return x; } Compile it by running $ cc -shared -o repro.so rep...
Opengraph URL: https://github.com/nodejs/node/issues/64880
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: refCallback()/unrefCallback() crash (SIGSEGV) when called on a garbage-collected callback","articleBody":"### Version\n\nmain\n\n### Platform\n\n```text\nN/A\n```\n\n### Subsystem\n\nffi\n\n### What steps will reproduce the bug?\n\n`repro.c`\n```c\n#include \u003cstdint.h>\n\nint32_t noop(int32_t x) { return x; }\n```\n\nCompile it by running\n```sh\n$ cc -shared -o repro.so repro.c # or .dylib on macOS\n```\n\n`repro.js`\n```js\nimport { DynamicLibrary, suffix } from 'node:ffi';\n\nconst lib = new DynamicLibrary(`./repro.${suffix}`);\n\nlet cb = (x) => x + 1;\nconst ptr = lib.registerCallback({ arguments: ['i32'], return: 'i32' }, cb);\n\n// Allow GC to collect the callback backing function\nlib.unrefCallback(ptr);\ncb = null;\nglobalThis.gc();\n\n// Second unref (or refCallback) on the now-empty weak handle → SIGSEGV\nlib.unrefCallback(ptr);\n\nlib.close();\n```\n\nRun it using\n```sh\n$ node --experimental-ffi --expose-gc --no-warnings repro.js\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`unrefCallback`/`refCallback` on a collected callback should throw `ERR_INVALID_ARG_VALUE(\"Callback not found\")`.\n\n### What do you see instead?\n\n```console\nsegmentation fault (core dumped)\n```\n\nThe process crashes with `SIGSEGV` inside `v8::PersistentBase::SetWeak()` (or `ClearWeak()` for refCallback) because the weak handle slot is already cleared after GC.\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-07-31T20:00:52Z","url":"https://github.com/nodejs/node/issues/64880"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:64c97573-39be-69d0-6c3a-4365a4afa30e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBF2:2B3418:3F2C79:522F59:6AED210D |
| html-safe-nonce | de55efb924a05109a1d7ad4e154705edb833cebfe10ac39f4c1bdaf69c2ef2ca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkYyOjJCMzQxODozRjJDNzk6NTIyRjU5OjZBRUQyMTBEIiwidmlzaXRvcl9pZCI6IjI1MzkxMDMzMTE5MTg2MDQ1NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0a8aaa1ef6e129fe08c923e5b55c6633ec38748ffc995576aca7756747df862e |
| hovercard-subject-tag | issue:5032963665 |
| 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/64880/issue_layout |
| twitter:image | https://opengraph.githubassets.com/855c366746dc9e32652da6c687b51dc615880b4ecdb5399d3f699226395627ca/nodejs/node/issues/64880 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/855c366746dc9e32652da6c687b51dc615880b4ecdb5399d3f699226395627ca/nodejs/node/issues/64880 |
| og:image:alt | Version main Platform N/A Subsystem ffi What steps will reproduce the bug? repro.c #include |
| 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 | e3e0f7f63e50c6fe879198a93a0a023a648ecc0a5e9bc3b5e033ac57172237e6 |
| 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 | 707a24b346ac8a82878b9c084efaa38a997660cb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width