File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ def try_create options = {} # :nodoc:
6363 if @created >= @max && @enqueued >= 1
6464 oldest , = @lru . first
6565 @lru . delete oldest
66- @ques [ oldest ] . pop
66+ connection = @ques [ oldest ] . pop
67+ connection . close if connection . respond_to? ( :close )
6768
6869 @created -= 1
6970 end
Original file line number Diff line number Diff line change 44class TestNetHttpPersistentTimedStackMulti < Minitest ::Test
55
66 class Connection
7- attr_reader :host
7+ attr_reader :host , :closed
88
99 def initialize ( host )
1010 @host = host
11+ @closed = false
12+ end
13+
14+ def close
15+ @closed = true
1116 end
1217 end
1318
@@ -69,6 +74,18 @@ def test_pop_full
6974 assert_empty stack
7075 end
7176
77+ def test_pop_closes_extra_connections
78+ stack = Net ::HTTP ::Persistent ::TimedStackMulti . new ( 1 ) { |host | Connection . new ( host ) }
79+
80+ a_conn = stack . pop connection_args : 'a.example'
81+ stack . push a_conn , connection_args : 'a.example'
82+
83+ b_conn = stack . pop connection_args : 'b.example'
84+
85+ assert a_conn . closed
86+ refute b_conn . closed
87+ end
88+
7289 def test_pop_wait
7390 thread = Thread . start do
7491 @stack . pop
You can’t perform that action at this time.
0 commit comments