diff --git a/lib/mongo/util/node.rb b/lib/mongo/util/node.rb index 5915d49..5fa691c 100644 --- a/lib/mongo/util/node.rb +++ b/lib/mongo/util/node.rb @@ -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 diff --git a/lib/mongo/util/tcp_socket.rb b/lib/mongo/util/tcp_socket.rb index 953eed7..b7f77ed 100644 --- a/lib/mongo/util/tcp_socket.rb +++ b/lib/mongo/util/tcp_socket.rb @@ -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) - @socket.readpartial(maxlen, buffer) + 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