Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enforce socket_timeout over select() loop

  • Loading branch information...
commit ad051d1e6f4352481346cad7c473334cc868a804 1 parent ec202d6
@tmm1 authored
Showing with 16 additions and 8 deletions.
  1. +16 −8 lib/dalli/client.rb
View
24 lib/dalli/client.rb
@@ -73,26 +73,34 @@ def get_multi(*keys)
end
end
- return {} if servers_in_use.empty?
+ values = {}
+ return values if servers_in_use.empty?
servers_in_use.each do |server|
+ next unless server.alive?
begin
- next unless server.alive?
server.multi_response_start
rescue NetworkError => e
servers_in_use.delete(server)
end
end
- values = {}
- while servers_in_use.any?
- timeout = servers_in_use.first.options[:socket_timeout]
+ start = Time.now
+ loop do
+ # remove any dead servers
servers_in_use.delete_if{ |s| s.sock.nil? }
- sockets = servers_in_use.map(&:sock)
- readable, _ = IO.select(sockets, nil, nil, timeout)
+ break if servers_in_use.empty?
+
+ timeout = servers_in_use.first.options[:socket_timeout]
+ if (Time.now - start) > timeout
+ readable = nil
+ else
+ readable, _ = IO.select(servers_in_use.map(&:sock), nil, nil, timeout)
+ end
if readable.nil?
- # mark all pending servers as failed
+ # no response within timeout
+ # abort pending connections and return known values
servers_in_use.each do |server|
server.multi_response_abort
end
Please sign in to comment.
Something went wrong with that request. Please try again.