From 7629cf30f09c8fafe4e37bd73eea2cad25733178 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 14 Dec 2010 15:53:59 -0500 Subject: [PATCH] Ensure that we close connection if receive raises any errors. --- lib/mongo/connection.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 52baeeb..b2ff882 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -750,9 +750,14 @@ module Mongo end def receive(sock, expected_response) + begin receive_header(sock, expected_response) number_received, cursor_id = receive_response_header(sock) read_documents(number_received, cursor_id, sock) + rescue Mongo::ConnectionFailure => ex + close + raise ex + end end def receive_header(sock, expected_response)