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
ffi: refCallback()/unrefCallback() crash (SIGSEGV) when called on a garbage-collected callback #64880
$ cc -shared -o repro.so repro.c # or .dylib on macOS
repro.js
import{DynamicLibrary,suffix}from'node:ffi';constlib=newDynamicLibrary(`./repro.${suffix}`);letcb=(x)=>x+1;constptr=lib.registerCallback({arguments: ['i32'],return: 'i32'},cb);// Allow GC to collect the callback backing functionlib.unrefCallback(ptr);cb=null;globalThis.gc();// Second unref (or refCallback) on the now-empty weak handle → SIGSEGVlib.unrefCallback(ptr);lib.close();
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
unrefCallback/refCallback on a collected callback should throw ERR_INVALID_ARG_VALUE("Callback not found").
What do you see instead?
segmentation fault (core dumped)
The process crashes with SIGSEGV inside v8::PersistentBase::SetWeak() (or ClearWeak() for refCallback) because the weak handle slot is already cleared after GC.
Activity
trivikr commentedon Jul 31, 2026
PR #64881
ffi: fix crash in refCallback and unrefCallback
ffi: fix crash in refCallback and unrefCallback
ffi: fix crash in refCallback and unrefCallback
ffi: fix crash in refCallback and unrefCallback
ffi: fix crash in refCallback and unrefCallback