Describe the bug
During a GET /stats request, we received the error message undefined method “reset_max” for nil (NoMethodError) @thread_pool.reset_max.
def stats
stats = @thread_pool&.stats || {} # considers that @thread_pool might be nil
stats[:max_threads] = @max_threads
stats[:requests_count] = @requests_count
stats[:reactor_max] = @reactor.reactor_max if @reactor
reset_max # calls reset_max
stats
end
def reset_max
@reactor.reactor_max = 0 if @reactor
@thread_pool.reset_max # does not consider @thread_pool to be nil
end
A quick look at the stack trace revealed that the method Puma::Server.reset_max does not consider @thread_pool to be nil. However, the calling method Puma::Server.stats considers @thread_pool to be nil. Therefore, I assume that reset_max, since it is called from stats, should apply the same consideration with regard to nil values.
Full Stack Trace
NoMethodError: undefined method 'reset_max' for nil (NoMethodError)
@thread_pool.reset_max
^^^^^^^^^^
from puma/server.rb:709:in 'reset_max'
from puma/server.rb:703:in 'stats'
from puma/single.rb:20:in 'stats'
from puma/launcher.rb:116:in 'stats'
from puma/app/status.rb:55:in 'call'
from puma/request.rb:101:in 'block in Puma::Request#handle_request'
from puma/thread_pool.rb:346:in 'with_force_shutdown'
from puma/request.rb:100:in 'handle_request'
from puma/server.rb:506:in 'process_client'
from puma/server.rb:265:in 'block in Puma::Server#run'
from puma/thread_pool.rb:173:in 'block in Puma::ThreadPool#spawn_thread'
To Reproduce
I'm actually not sure how we managed to cause it. Maybe just bad timing during shutdown? (wild guess)
Desktop (please complete the following information):
- OS: Linux
- Ruby: 3.4.2
- Puma: 7.0.4
Describe the bug
During a
GET /statsrequest, we received the error messageundefined method “reset_max” for nil (NoMethodError) @thread_pool.reset_max.A quick look at the stack trace revealed that the method
Puma::Server.reset_maxdoes not consider@thread_poolto benil. However, the calling methodPuma::Server.statsconsiders@thread_poolto be nil. Therefore, I assume thatreset_max, since it is called fromstats, should apply the same consideration with regard to nil values.puma/lib/puma/server.rb
Line 709 in a23e6bd
Full Stack Trace
To Reproduce
I'm actually not sure how we managed to cause it. Maybe just bad timing during shutdown? (wild guess)
Desktop (please complete the following information):