From: Eric Hodel Date: 2007-12-25T09:36:12+09:00 Subject: Timeout.timeout expires early - breaks RubyGems Sometimes Timeout.timeout expires early. I see this with `gem install` frequently because it fetches a large file. The following test fetches a 10MB file from http://izmunuti.segment7.net/~drbrain/zeros (all NULL) and shows a Timeout::Error being raised after an impossibly small timeout. Occasionally the fetch will complete, but usually the errors are between 150 and 300 iterations of the loop. The code is based on Net::HTTP $ svnversion 14640 $ cat test.rb require 'socket' require 'timeout' s = TCPSocket.new 'izmunuti.segment7.net', '80' s.syswrite "GET /~drbrain/zeros HTTP/1.0\r\n" s.syswrite "Host: segment7.net\r\n" s.syswrite "\r\n" buf = [] bufsize = 1024 * 16 loop do begin start = Time.now timeout 60 do buf << s.sysread(bufsize) end rescue Timeout::Error puts "timeout after #{Time.now - start} and #{buf.length} sysreads" raise end end p buf.length $ ./miniruby ./runruby.rb --extout=.ext -- test.rb timeout after 0.000361 and 1590 sysreads test.rb:18:in `sysread': execution expired (Timeout::Error) from test.rb:18:in `block (2 levels) in
' from /Users/drbrain/Work/svn/ruby/trunk/lib/timeout.rb:46:in `timeout' from /Users/drbrain/Work/svn/ruby/trunk/lib/timeout.rb:65:in `timeout' from test.rb:17:in `block in
' from test.rb:13:in `loop' from test.rb:13:in `
'