puma icon indicating copy to clipboard operation
puma copied to clipboard

`NoMethodError` on `NilClass` under JRuby

Open brian-goldman opened this issue 3 months ago • 4 comments

Describe the bug

When using the system JRuby in Debian Trixie (JRuby 9.4.8.0, OpenJDK 21.0.8), I get the following error in the console output on every request, with no backtrace:

Error reached top of thread-pool: undefined method `>=' for nil:NilClass (NoMethodError)

Puma config:

I'm running the command puma with the following config.ru:

run (Proc.new do
  [200, {}, ['hi']]
end)

To Reproduce

  • Start with a fresh install of Debian 13
  • apt install jruby
  • jruby -S gem install puma
  • jruby -S puma (with the above config.ru)

Expected behavior

"hi" in the browser.

Desktop

  • Debian 13, Trixie (running on OrbStack on a Mac M1)
  • Puma 7.0.3, Romantic Warrior

brian-goldman avatar Sep 22 '25 18:09 brian-goldman

I patched thread_pool.rb to get this backtrace:

Error reached top of thread-pool: undefined method `>=' for nil:NilClass (NoMethodError)
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/server.rb:217:in `closed_socket?'
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/request.rb:176:in `prepare_response'
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/server.rb:596:in `response_to_error'
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/server.rb:568:in `client_error'
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/server.rb:526:in `process_client'
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/server.rb:266:in `block in run'
/usr/share/jruby/lib/ruby/gems/shared/gems/puma-7.0.3-java/lib/puma/thread_pool.rb:173:in `block in spawn_thread'

brian-goldman avatar Sep 22 '25 18:09 brian-goldman

@brian-goldman

Thanks for the report.

https://github.com/puma/puma/blob/ef2c6aae78a5df5ceb6126045768e474fe2b51be/lib/puma/server.rb#L209-L218

This might be platform/OS dependent. Can you try adding the following line between 216 & 217?

return false unless state

MSP-Greg avatar Sep 22 '25 18:09 MSP-Greg

That fixes it.

brian-goldman avatar Sep 22 '25 18:09 brian-goldman

Interesting. The code works with curl on Ubuntu (I already had JRuby 9.4.8.0 installed). Regardless, easy fix and the statement is 'low-overhead'... PR soon.

MSP-Greg avatar Sep 22 '25 18:09 MSP-Greg