diff --git a/lib/net/http/persistent.rb b/lib/net/http/persistent.rb index e1fadbc..ad66842 100644 --- a/lib/net/http/persistent.rb +++ b/lib/net/http/persistent.rb @@ -1048,9 +1048,7 @@ def request_setup req_or_uri # :nodoc: # #shutdown when you are completely done making requests! def shutdown - @pool.available.shutdown do |http| - http.finish - end + @pool.shutdown { |http| http.finish } end ## diff --git a/lib/net/http/persistent/pool.rb b/lib/net/http/persistent/pool.rb index b88dd59..90fd92b 100644 --- a/lib/net/http/persistent/pool.rb +++ b/lib/net/http/persistent/pool.rb @@ -7,11 +7,11 @@ def initialize(options = {}, &block) super @available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block) - @key = :"current-#{@available.object_id}" + @key = "current-#{@available.object_id}" end def checkin net_http_args - stack = Thread.current[@key][net_http_args] + stack = Thread.current[@key][net_http_args] ||= [] raise ConnectionPool::Error, 'no connections are checked out' if stack.empty? @@ -26,8 +26,8 @@ def checkin net_http_args end def checkout net_http_args - stacks = Thread.current[@key] ||= Hash.new { |h, k| h[k] = [] } - stack = stacks[net_http_args] + stacks = Thread.current[@key] ||= {} + stack = stacks[net_http_args] ||= [] if stack.empty? then conn = @available.pop connection_args: net_http_args @@ -40,6 +40,10 @@ def checkout net_http_args conn end + def shutdown + Thread.current[@key] = nil + super + end end require 'net/http/persistent/timed_stack_multi'