From: Brian Candler Date: 2004-10-06T20:36:28+09:00 Subject: Re: Timeout error? On Tue, Oct 05, 2004 at 02:04:53PM +0900, Mark Probert wrote: > I guess the real qustion is why Timeout::Error doesn't trap > Errno::ETIMEDOUT. The socket times out before the timeout() and raises a > different timeout error. Perhaps it would be better if, when a block is > wrapped in a Timeout::timeout, that all subservient timeouts should be > caught by the single rescue. > > It does raise the question why the generic rescue isn't triggered. It is for me (ruby-1.8.2p2, FreeBSD), so perhaps this is either a Windows platform issue, or something from 1.8.1 which has been fixed. $ cat foo.rb require 'socket' require 'timeout' def alive?(host,port) ok = false begin Timeout::timeout(30) { begin t = TCPSocket.new(host,port) # <--- line 150 t.close ok = true rescue Exception => e # why not caught here? @exception = e end } rescue Timeout::Error => e # or here? @exception = e end return ok end p alive?('192.0.2.1',1234) $ time ruby foo.rb false real 0m30.299s user 0m0.076s sys 0m0.024s << change timeout to 120 >> $ time ruby foo.rb false real 1m15.155s user 0m0.074s sys 0m0.025s (75 secs is the default TCP SYN timeout in FreeBSD) Regards, Brian.