-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.5.2
-
Component/s: None
I'm trying to save in this way (based on http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html)
rescue_connection_failure do
@db.collection('users').insert({}, :safe => true)
end
Most of the cases when primary node goes down it works well because a Mongo::ConnectionFailure exception is raised and the block will try again until a new primary is available.
However, when it tries to insert data for the first time, a Mongo::OperationFailure is raised. The following attempts will raise Mongo::ConnectionFailure as excepted, until a master is available.
I'm assuming that we always want to raise a Mongo::ConnectionFailure when the error returned by the server is like "not master", please take a look at my pull request and let me know if I'm assuming wrong.
This is the test I have in my pull request with the fix, it shows how reproduce this error:
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]])
primary = Mongo::Connection.new(@conn.primary_pool.host, @conn.primary_pool.port)
primary['admin'].command({:replSetStepDown => 60})
( This is failing in 1.5.2 because it raises OperationFailure instead of ConnectionFailure )
rescue_connection_failure do
@conn[MONGO_TEST_DB]['bar'].save({:a => 1}, {:safe => {:w => 3}})
end