From cb3717c084a2da218e98034b0c9592e3b21facf8 Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Tue, 26 Aug 2014 20:57:37 +0200 Subject: [PATCH 1/2] Use Retry failover strategy for AuthenticationFailure When the replica set is reconfigured or a node is in startup mode this can cause authentication errors. We now use the Retry failover strategy in this case so we try again and mark the node as down if the operation fails again. --- lib/moped/failover.rb | 2 +- spec/moped/failover_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/moped/failover.rb b/lib/moped/failover.rb index d893adc..b9df93a 100644 --- a/lib/moped/failover.rb +++ b/lib/moped/failover.rb @@ -17,7 +17,7 @@ module Failover # # @since 2.0.0 STRATEGIES = { - Errors::AuthenticationFailure => Ignore, + Errors::AuthenticationFailure => Retry, Errors::ConnectionFailure => Retry, Errors::CursorNotFound => Ignore, Errors::OperationFailure => Reconfigure, diff --git a/spec/moped/failover_spec.rb b/spec/moped/failover_spec.rb index ff0833e..51aa7ba 100644 --- a/spec/moped/failover_spec.rb +++ b/spec/moped/failover_spec.rb @@ -56,8 +56,8 @@ described_class.get(Moped::Errors::AuthenticationFailure.new({}, {})) end - it "returns an ignore" do - expect(failover).to be_a(Moped::Failover::Ignore) + it "returns a retry" do + expect(failover).to be_a(Moped::Failover::Retry) end end From 92d18b1070d4351dff328b6865970249f8c826ca Mon Sep 17 00:00:00 2001 From: Robert Beekman Date: Wed, 27 Aug 2014 14:46:03 +0200 Subject: [PATCH 2/2] Disconnect from node when authentication fails --- lib/moped/operation/read.rb | 1 + spec/moped/operation/read_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/moped/operation/read.rb b/lib/moped/operation/read.rb index cd6c96b..1a2c383 100644 --- a/lib/moped/operation/read.rb +++ b/lib/moped/operation/read.rb @@ -47,6 +47,7 @@ def initialize(operation) def execute(node) node.process(operation) do |reply| if operation.failure?(reply) + node.down! if reply.unauthorized? raise operation.failure_exception(reply) end operation.results(reply) diff --git a/spec/moped/operation/read_spec.rb b/spec/moped/operation/read_spec.rb index 1d7e4b2..80009fa 100644 --- a/spec/moped/operation/read_spec.rb +++ b/spec/moped/operation/read_spec.rb @@ -39,6 +39,11 @@ replica_set_node.unauthorized_on_next_message! end + it "should mark the node as down" do + expect(node).to receive(:down!) + read.execute(node) rescue nil + end + it "raises a failure error" do expect { read.execute(node) @@ -53,6 +58,10 @@ replica_set_node.query_failure_on_next_message! end + it "should not mark the node as down" do + expect(node).to_not receive(:down!) + end + it "raises a failure error" do expect { read.execute(node)