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

Commit

Permalink
Merge "Fix the redis warning: Could not cleanup instance, the reasons…
Browse files Browse the repository at this point in the history
…: ["ERR max number of clients reached"]" into services-r10
  • Loading branch information
Tang Rui authored and Gerrit Code Review committed Mar 23, 2012
2 parents 493fc4c + d45578d commit a3de99a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
19 changes: 19 additions & 0 deletions redis/lib/redis_service/redis_node.rb
Expand Up @@ -49,6 +49,25 @@ def listening?
def running?
VCAP.process_running? pid
end

def kill(sig=:SIGTERM)
@wait_thread = Process.detach(pid)
Process.kill(sig, pid) if running?
end

def wait_killed(timeout=5, interval=0.2)
begin
Timeout::timeout(timeout) do
@wait_thread.join if @wait_thread
while running? do
sleep interval
end
end
rescue Timeout::Error
return false
end
true
end
end

def initialize(options)
Expand Down
16 changes: 12 additions & 4 deletions redis/lib/redis_service/util.rb
Expand Up @@ -185,10 +185,18 @@ def stop_redis_server(instance)
begin
redis.shutdown(@shutdown_command_name)
rescue RuntimeError => e
# It could be a disabled instance
if @disable_password
redis = ::Redis.new({:port => instance.port, :password => @disable_password})
redis.shutdown(@shutdown_command_name)
if e.message == "ERR max number of clients reached"
# The max clients limitation could be reached, try to kill the process
instance.kill
instance.wait_killed ?
@logger.debug("Redis server pid: #{instance.pid} terminated") :
@logger.error("Timeout to terminate Redis server pid: #{instance.pid}")
else
# It could be a disabled instance
if @disable_password
redis = ::Redis.new({:port => instance.port, :password => @disable_password})
redis.shutdown(@shutdown_command_name)
end
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions redis/spec/node_spec.rb
Expand Up @@ -461,6 +461,18 @@ class Node
Redis.new({:port => @credentials["port"], :password => @credentials["password"]}).info
@node.unprovision(@credentials["name"])
end

it "should unprovision successfully when reach the maximum number of clients" do
@credentials = @node.provision(:free)
sleep 1
redis = []
# Create max_clients connections
for i in 1..@options[:max_clients]
redis[i] = Redis.new({:port => @credentials["port"], :password => @credentials["password"]})
redis[i].info
end
@node.unprovision(@credentials["name"]).should == {}
end
end

describe "Node.timeout" do
Expand Down

0 comments on commit a3de99a

Please sign in to comment.