From 7ec1aa3cfa1225f1bab0aa4cae516782d4553f7a Mon Sep 17 00:00:00 2001 From: Chris Heald Date: Tue, 1 Mar 2016 12:57:48 -0700 Subject: [PATCH] Ensure that ping test clients are always disconnected after use. Don't assume that a good slave was found. --- lib/redis/client.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/redis/client.rb b/lib/redis/client.rb index af2f2326d..695ca71bb 100755 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -584,15 +584,18 @@ def resolve_nearest_slave :port => slave["port"], :reconnect_attempts => 0 ) - client.call [:ping] - start = Time.now - client.call [:ping] - slave["response_time"] = (Time.now - start).to_f - client.disconnect + begin + client.call [:ping] + start = Time.now + client.call [:ping] + slave["response_time"] = (Time.now - start).to_f + ensure + client.disconnect + end end slave = ok_slaves.sort_by {|slave| slave["response_time"] }.first - {:host => slave.fetch("ip"), :port => slave.fetch("port")} + {:host => slave.fetch("ip"), :port => slave.fetch("port")} if slave end end end