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
3 changes: 2 additions & 1 deletion lib/net/http/persistent/timed_stack_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def try_create options = {} # :nodoc:
if @created >= @max && @enqueued >= 1
oldest, = @lru.first
@lru.delete oldest
@ques[oldest].pop
connection = @ques[oldest].pop
connection.close if connection.respond_to?(:close)

@created -= 1
end
Expand Down
19 changes: 18 additions & 1 deletion test/test_net_http_persistent_timed_stack_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
class TestNetHttpPersistentTimedStackMulti < Minitest::Test

class Connection
attr_reader :host
attr_reader :host, :closed

def initialize(host)
@host = host
@closed = false
end

def close
@closed = true
end
end

Expand Down Expand Up @@ -69,6 +74,18 @@ def test_pop_full
assert_empty stack
end

def test_pop_closes_extra_connections
stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { |host| Connection.new(host) }

a_conn = stack.pop connection_args: 'a.example'
stack.push a_conn, connection_args: 'a.example'

b_conn = stack.pop connection_args: 'b.example'

assert a_conn.closed
refute b_conn.closed
end

def test_pop_wait
thread = Thread.start do
@stack.pop
Expand Down
Loading