From 76bf4dffe5d29a0eedf8a70ee399a88fed506ecd Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Wed, 4 Apr 2012 13:46:47 -0400 Subject: [PATCH] RUBY-429 rescue and raise appropriate errors --- lib/mongo/util/node.rb | 2 +- lib/mongo/util/tcp_socket.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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