1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Merge pull request #2295 from looker/looker/thread_pool_count1

resolve waiting counter problem
This commit is contained in:
Nate Berkopec 2020-06-12 08:41:47 +09:00 committed by GitHub
commit a72c68b350
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View file

@ -1,3 +1,7 @@
### Master
* Bugfixes
* Resolve issue with threadpool waiting counter decrement when thread is killed
## 5.0.0
* Features

View file

@ -122,8 +122,11 @@ module Puma
@out_of_band_pending = false
end
not_full.signal
not_empty.wait mutex
@waiting -= 1
begin
not_empty.wait mutex
ensure
@waiting -= 1
end
end
work = todo.shift

View file

@ -266,4 +266,19 @@ class TestThreadPool < Minitest::Test
assert_equal 2, rescued.length
refute rescued.compact.any?(&:alive?)
end
def test_correct_waiting_count_for_killed_threads
pool = new_pool(1, 1) { |_| }
sleep 1
# simulate our waiting worker thread getting killed for whatever reason
pool.instance_eval { @workers[0].kill }
sleep 1
pool.reap
sleep 1
pool << 0
sleep 1
assert_equal 0, pool.backlog
end
end