RUBY-429 rescue and raise appropriate errors

This commit is contained in:
Tyler Brock 2012-04-04 13:46:47 -04:00
parent 92af319412
commit 76bf4dffe5
2 changed files with 9 additions and 3 deletions

View File

@ -45,7 +45,7 @@ module Mongo
else
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
rescue OperationTimeout, OperationFailure, SocketError, SystemCallError, IOError => ex
rescue OperationTimeout, ConnectionFailure, OperationFailure, SocketError, SystemCallError, IOError => ex
@connection.log(:debug, "Failed connection to #{host_string} with #{ex.class}, #{ex.message}.")
socket.close if socket
return nil

View File

@ -60,8 +60,14 @@ module Mongo
def read(maxlen, buffer)
# Block on data to read for @op_timeout seconds
if IO.select([@socket], nil, nil, @op_timeout)
if IO.select([@socket], nil, [@socket], @op_timeout)
begin
@socket.readpartial(maxlen, buffer)
rescue EOFError
return ConnectionError
rescue Errno::ECONNRESET
raise ConnectionFailure
end
else
raise OperationTimeout
end