Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
12 changes: 8 additions & 4 deletions lib/net/http/persistent/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand All @@ -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'
Expand Down