Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if @zk is not connected redis-failover will sit there in an infinite loo... #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/redis_failover/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def initialize(options = {})
@slaves = []
@node_addresses = {}
@lock = Monitor.new
@shutdown = false
@current_client_key = "current-client-#{self.object_id}"
yield self if block_given?

Expand Down Expand Up @@ -145,15 +146,17 @@ def manual_failover(options = {})
# and then create a new instance of the client. The underlying
# ZooKeeper client and redis clients will be closed.
def shutdown
@zk.close! if @zk
@zk.close! if @zk and @zk.connected?
@zk = nil
@shutdown = true
purge_clients
end

# Reconnect will first perform a shutdown of the underlying redis clients.
# Next, it attempts to reopen the ZooKeeper client and re-create the redis
# clients after it fetches the most up-to-date list from ZooKeeper.
def reconnect
@shutdown = false
purge_clients
@zk ? @zk.reopen : setup_zk
build_clients
Expand Down Expand Up @@ -319,12 +322,22 @@ def fetch_nodes
nodes
rescue Zookeeper::Exceptions::InheritedConnectionError => ex
logger.debug { "Caught #{ex.class} '#{ex.message}' - reopening ZK client" }
@zk.reopen
retry
unless @shutdown
@zk.reopen
retry
end
rescue Zookeeper::Exceptions::NotConnected => ex
logger.warn { "Caught #{ex.class} '#{ex.message}' - reopening ZK client" }
unless @shutdown
@zk.reopen
retry
end
rescue *ZK_ERRORS => ex
logger.warn { "Caught #{ex.class} '#{ex.message}' - retrying" }
sleep(RETRY_WAIT_TIME)
retry
unless @shutdown
sleep(RETRY_WAIT_TIME)
retry
end
end

# Builds new Redis clients for the specified nodes.
Expand Down