diff --git a/Rakefile b/Rakefile index 198c9e9..9182837 100644 --- a/Rakefile +++ b/Rakefile @@ -76,6 +76,11 @@ namespace :test do t.verbose = true end + Rake::TestTask.new(:auto_reconnect) do |t| + t.test_files = FileList['test/auxillary/autoreconnect_test.rb'] + t.verbose = true + end + task :drop_databases do |t| puts "Dropping test database..." require File.join(File.dirname(__FILE__), 'lib', 'mongo') diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 07130cc..a28eff8 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -321,6 +321,7 @@ module Mongo break if is_master || @slave_ok rescue SocketError, SystemCallError, IOError => ex socket.close if socket + close false end end @@ -513,6 +514,7 @@ module Mongo message += chunk end rescue => ex + close raise ConnectionFailure, "Operation failed with the following exception: #{ex}" end message