Skip to content
Browse files

[BUG FIX] replica set reconfiguration handled gracefully for updates

It only with when using safe: true, otherwise data gets lost...

Stack trace:
  Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
    @selector={:getlasterror=>1, :safe=>true}
  failed with error 10054: "not master"
  • Loading branch information...
1 parent 089edac commit 6d7d12a0da13923c5fbf9c72a17859743b6eab43 @nviennot committed Oct 8, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/moped/node.rb
9 lib/moped/node.rb
@@ -133,7 +133,14 @@ def ensure_connected
raise Errors::ReplicaSetReconfigured
- rescue Errors::OperationFailure, Errors::AuthenticationFailure, Errors::CursorNotFound
+ rescue Errors::OperationFailure => e
+ # We might have a replica set change with:
+ # "failed with error 10054: "not master"
+ if e.details['code'] == 10054
+ raise Errors::ReplicaSetReconfigured
+ end
+ raise
+ rescue Errors::AuthenticationFailure, Errors::CursorNotFound
# These exceptions are "expected" in the normal course of events, and
# don't necessitate disconnecting.

0 comments on commit 6d7d12a

Please sign in to comment.
Something went wrong with that request. Please try again.