Bug #2828

Timeout doesn't work as expected if ruby process blocks

Added by Florian Eitel almost 2 years ago. Updated 10 months ago.

[ruby-core:28380]
Status:Rejected Start date:02/24/2010
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
ruby -v:ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

Description

> TCPSocket.new "fireflyseason2.com", "echo"

Blocks ruby process for a while because the domain is not available. If you would try to surround it with an timeout Block (timeout.rb) this will not work because of blocking:

> timeout(timeout) do TCPSocket.new("fireflyseason2.com", "echo") end

But pingecho(..) in ping.rb is trying exactly this behavior. Is this a Bug or OS specific behavior?

The complete blocking of all threads in combination with timeout can result strange errors:

> timeout(5) do TCPSocket.new("fireflyseason2.com", "echo").close end

This should raise a "Timeout::Error: execution expired" exception. (in result of blocking of course not after 5 sec but some time later...). But sometimes a strange "#<Class:0xb7c7a2ec>: execution expired" exception is thrown. In my opinion there is a race condition between two exception.

TCPSocket.new blocks ruby process and blocks all threads. The thread which should throw an exception after timeout is blocked as well. After TCPSocket ends blocking everything is running again. TCPSocket raises an exception because open is failed. At the same time the timeout thread is raised an exception as well (see timeout.rb:60). This should catched in timeout:64 but I think the exception of TCPSocket came first and passed already the rescue/ensure block. As an result the timeout exception is not caught in timeout method and the caller receives it.

I'm not completely sure about this but in my opinion this is the only possibility which lead into this strange error. The error happens not every time. It depends of course on network setup (if TCPSocket is used for blocking) and perhaps some other factors.

For complete example please look at http://gist.github.com/312336

History

Updated by Shyouhei Urabe over 1 year ago

  • Status changed from Open to Rejected

Also available in: Atom PDF