Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
timeout method not calling Timeout::timeout #3158
I'm supporting and using a library which overwrites the timeout method:
It's kind of a "monkey-patch-fu" extension for celluloid, as celluloid has its own timeout method and currently ruby doesn't support an API for switching timeout methods depending of method.
But in JRuby (188.8.131.52.rc2) it seems that timeout and Timeout::timeout are not the same. Calling timeout jumps straight to the Java implementation, which breaks this patch. So, instead of one, I have to patch two methods for JRuby. Should JRuby follow the standard from MRI in this case, or is there a reason? I would prefer not to patch the same thing two times.
Interesting. I would have expected that these methods were implemented like other module methods, with two copies of the method in two method tables, but I suppose in MRI the instance method just dispatches to the class method. That's not a difficult change to make.
I expect this affects 1.7 too.
Humm... it's interesting, according to this, you are right, it should.
I tried patching the Kernel.timeout, even:
and, if I see load it in the console, it's overwritten:
But then, in a script, doing something inside TCPSocket class from Celluloid (using debugger):
this call to timeout jumps to the jruby implementation, according to the backtrace I receive:
(the available_for_read? method calls the timeout method, should have jumped to the timeout-extensions method).
Maybe has to do with alias_method?
I figured the issue out. In MRI, where timeout is pure Ruby, the top-level
# Identical to: # # Timeout::timeout(n, e, &block). # # This method is deprecated and provided only for backwards compatibility. # You should use Timeout#timeout instead. def timeout(n, e = nil, &block) Timeout::timeout(n, e, &block) end
Note the deprecation.
In JRuby, it's defined as a direct static call in Java to the actual implementation. The Timeout::timeout method is defined as a normal module method in both MRI and JRuby, though, so that part's ok.
I'll have a fix for this momentarily. Thanks for the report!