Subject:
Re: [ruby-ffi] ruby 1.9.1 crashing when executing callback
From:
Chuck Remes
Date:
5/12/10 4:24 PM
To:
ruby-ffi@googlegroups.com


On May 12, 2010, at 2:53 PM, Chuck Remes wrote:

> I'm starting to work with callbacks and have run into a consistent crasher. Take a look at the trace here:
> 
> http://gist.github.com/398987
> 
> I downloaded the ruby-1.9.1 source and poked through vm_eval.c which contains the vm_call0() function. There is a big switch statement in there that falls through to calling rb_bug(). 
> 
> This all occurs *only* when invoking the callback. The stack trace clearly shows it is invoking a block (rb_funcall2) from the FFI library. It crashes regardless of the contents of the block (empty, puts, nil, etc.).
> 
> In 1.8.7 it crashes with a LocalJumpError somewhere else.
> 
> When I disable the callback, there are no crashes under either MRI.
> 
> Under JRuby, everything works fine. The callback is invoked successfully.
> 
> I'm wondering if this is failing because the callback may be invoked by another native thread. The library being wrapped by FFI spawns many threads that do various background tasks; one of them is likely the invocation of the cleanup callback that is causing the crash.
> 
> Are there any known issues with MRI, FFI and callbacks?

BTW, it doesn't matter if the callback is a Proc, proc or FFI::Function, it still crashes. I also experimented with :blocking => true (for FFI::Function) and it didn't help at all.

I'd report this to ruby-core but they'll need a reduced test case to reproduce. I don't have the skills to make a small C library that spawns a few threads, lets me register a callback and then have it fired. I think such a test lib would be sufficient to show the crash.

cr