Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
flush connection credentials to force a new login after an authentica…
Browse files Browse the repository at this point in the history
…tion/authorization error
  • Loading branch information
wandenberg committed Jun 3, 2015
1 parent 49f65ef commit 372f22a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/moped/node.rb
Expand Up @@ -162,6 +162,12 @@ def down!
Connection::Manager.shutdown(self)
end

def flush_connection_credentials
connection do |conn|
conn.credentials.clear
end
end

# Yields the block if a connection can be established, retrying when a
# connection error is raised.
#
Expand Down
5 changes: 3 additions & 2 deletions lib/moped/retryable.rb
Expand Up @@ -29,12 +29,13 @@ def with_retry(cluster, retries = cluster.max_retries, &block)
begin
block.call
rescue Errors::ConnectionFailure, Errors::PotentialReconfiguration => e
raise e if e.is_a?(Errors::PotentialReconfiguration) &&
! (e.message.include?("not master") || e.message.include?("Not primary"))
authentication_error = e.is_a?(Errors::PotentialReconfiguration) && e.message.match(/not (master|primary|authorized)/i)
raise e if e.is_a?(Errors::PotentialReconfiguration) && !authentication_error

if retries > 0
Loggable.warn(" MOPED:", "Retrying connection attempt #{retries} more time(s).", "n/a")
sleep(cluster.retry_interval)
cluster.nodes.each { |node| node.flush_connection_credentials } if authentication_error
cluster.refresh
with_retry(cluster, retries - 1, &block)
else
Expand Down

0 comments on commit 372f22a

Please sign in to comment.