diff options
author | Bryan Duxbury <bryanduxbury@apache.org> | 2010-09-17 20:17:21 +0000 |
---|---|---|
committer | Bryan Duxbury <bryanduxbury@apache.org> | 2010-09-17 20:17:21 +0000 |
commit | 83c47958707956a8812b2c5c91a4550f874cb055 (patch) | |
tree | 45ce71e9b34d618c29e42b04fc4eb399842f6db9 /lib/rb/lib | |
parent | d920765c66472d0011a7c6b3c8ce612317fa3801 (diff) | |
download | thrift-83c47958707956a8812b2c5c91a4550f874cb055.tar.gz |
THRIFT-899. rb: Ruby read timeouts can sometimes be 2x what they should be
This patch makes sure that we don't wait longer than necessary for timeouts.
Patch: Ryan King
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@998303 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib/rb/lib')
-rw-r--r-- | lib/rb/lib/thrift/transport/socket.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb index 06c937e58..9bb20361f 100644 --- a/lib/rb/lib/thrift/transport/socket.rb +++ b/lib/rb/lib/thrift/transport/socket.rb @@ -97,12 +97,13 @@ module Thrift data = @handle.readpartial(sz) else # it's possible to interrupt select for something other than the timeout - # so we need to ensure we've waited long enough + # so we need to ensure we've waited long enough, but not too long start = Time.now - rd = nil # scoping - loop do - rd, = IO.select([@handle], nil, nil, @timeout) - break if (rd and not rd.empty?) or Time.now - start >= @timeout + timespent = 0 + rd = loop do + rd, = IO.select([@handle], nil, nil, @timeout - timespent) + timespent = Time.now - start + break rd if (rd and not rd.empty?) or timespent >= @timeout end if rd.nil? or rd.empty? raise TransportException.new(TransportException::TIMED_OUT, "Socket: Timed out reading #{sz} bytes from #{@desc}") |