Jruby timeouts not reliable?

I know that in ruby (due to green threads), timeout.rb is a mess when
dealing with system calls, but I thought (until now) that in jruby did
not exist this problem.

I’m gonna use ffi to be able to use native code:

sleep_c.c:
// If input parameter is 0, infinite loop, otherwise sleep x seconds
void sleep_c(int s)
{
if ( ! s ) while (1) ++s;
sleep(s);
}

gcc -shared sleep_c.c -o libsleep_c.so

sleep.rb:
require ‘ffi’
module Foo
extend FFI::Library
ffi_lib File.join(File.dirname(FILE), “libsleep_c.so”)
attach_function :sleep_c, [:int], :void
end

require ‘timeout’
Timeout.timeout(1) do
timeout = ARGV[0].to_i
Foo.sleep_c timeout
end

If you execute jruby sleep_c.rb 2 (a sleep 2 system call is executed)
will end with timeout exception as expected, ok. But, if you execute
jruby sleep_c.rb 0 (infinite loop in native code), it will never end.
Is this a problem with jruby, with ffi or with something else?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Its an FFI/threading interaction problem. Timeout should be 100%
reliable when accessing regular ruby methods, and I/O, but calling an
ffi function that enters an infinite cpu loop, its not going to be
able to interrupt it.

I have no idea if thats really fixable. Definitely not in the short
term.

2010/6/8 Jesús García Sáez [email protected]:

if ( ! s ) while (1) ++s;
ffi_lib File.join(File.dirname(FILE), “libsleep_c.so”)
If you execute jruby sleep_c.rb 2 (a sleep 2 system call is executed)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email