Debugging a failed node-ffi callback / segmentation fault

1.5k Views Asked by At

I'm trying to use libvlc from within node.js using node-ffi, and while it seems to work great for the general basic media player functionality, I keep getting crashes, segmentation faults and general freezes in my program when I try to use libvlc's asynchronous event system and integrate it with node's EventEmitter. The code I'm using thus far is hosted at https://gist.github.com/2644721 but doesn't seem to work.

GDB produces a mixed-bag of results, but the last crash I received was:

Program received signal SIGSEGV, Segmentation fault.
0x000000000057cc86 in v8::Function::Call(v8::Handle<v8::Object>, int, v8::Handle<v8::Value>*) ()
(gdb) bt
#0  0x000000000057cc86 in v8::Function::Call(v8::Handle<v8::Object>, int, v8::Handle<v8::Value>*) ()
#1  0x00007ffff5997a41 in CallbackInfo::DispatchToV8(CallbackInfo*, void*, void**) ()
   from /home/adam/node_modules/node-ffi/compiled/0.6/linux/x64/ffi_bindings.node
#2  0x00007ffff5997adb in CallbackInfo::WatcherCallback(uv_async_s*, int) ()
   from /home/adam/node_modules/node-ffi/compiled/0.6/linux/x64/ffi_bindings.node
#3  0x00000000007be12f in ev_invoke_pending ()
#4  0x00000000007c2087 in ev_run ()
#5  0x00000000007b597f in uv_run ()
#6  0x000000000052a147 in node::Start(int, char**) ()
#7  0x00007ffff63ca76d in __libc_start_main ()
   from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000000000524fe5 in _start ()

It's obvious I'm doing something wrong here - node-ffi documentation say that it's really easy to cause this sort of behaviour if you do something wrong. I'm thinking perhaps the callback isn't being run from the same thread or scope, but I'm not sure how to check or even fix that. Any help would be appreciated...

Program received signal SIGSEGV, Segmentation fault.
IsGlobalObject (this=0x1)
    at /build/buildd/nodejs-0.6.17/deps/v8/src/objects-inl.h:796
796 in /build/buildd/nodejs-0.6.17/deps/v8/src/objects-inl.h
(gdb) bt
#0  IsGlobalObject (this=0x1)
    at /build/buildd/nodejs-0.6.17/deps/v8/src/objects-inl.h:796
#1  v8::internal::Invoke (construct=<optimised out>, func=..., receiver=..., 
    argc=2, args=0x7fffffffdeb0, has_pending_exception=0x7fffffffde1f)
    at /build/buildd/nodejs-0.6.17/deps/v8/src/execution.cc:101
#2  0x00000000005ae967 in v8::internal::Execution::Call (callable=..., 
    receiver=..., argc=2, args=0x7fffffffdeb0, 
    pending_exception=0x7fffffffde1f, convert_receiver=<optimised out>)
    at /build/buildd/nodejs-0.6.17/deps/v8/src/execution.cc:175
#3  0x000000000057cd31 in v8::Function::Call (this=0xc0aae0, recv=..., argc=2, 
    argv=0x7fffffffdeb0) at /build/buildd/nodejs-0.6.17/deps/v8/src/api.cc:3601
#4  0x00007ffff5997a41 in CallbackInfo::DispatchToV8(CallbackInfo*, void*, void**) ()
   from /home/adam/node_modules/node-ffi/compiled/0.6/linux/x64/ffi_bindings.node
#5  0x00007ffff5997adb in CallbackInfo::WatcherCallback(uv_async_s*, int) ()
   from /home/adam/node_modules/node-ffi/compiled/0.6/linux/x64/ffi_bindings.node
#6  0x00000000007be12f in ev_invoke_pending (loop=0xb9dea0)
    at src/unix/ev/ev.c:2149
#7  0x00000000007c2087 in ev_run (loop=0xb9dea0, flags=0)
    at src/unix/ev/ev.c:2525
#8  0x00000000007b597f in uv_run (loop=<optimised out>) at src/unix/core.c:194
0

There are 0 best solutions below