yabeda-rb / yabeda-puma-plugin

Collects Puma web-server metrics from puma control panel
MIT License
70 stars 17 forks source link

undefined method `stop' for nil:NilClass #26

Closed wvengen closed 1 year ago

wvengen commented 2 years ago

Sometimes I'm getting this error:

gems/yabeda-puma-plugin-0.7.0/lib/puma/plugin/yabeda_prometheus.rb:74:in `block in start': undefined method `stop' for nil:NilClass (NoMethodError)
    from gems/puma-5.6.5/lib/puma/events.rb:45:in `block in fire'
    from gems/puma-5.6.5/lib/puma/events.rb:45:in `each'
    from gems/puma-5.6.5/lib/puma/events.rb:45:in `fire'
    from gems/puma-5.6.5/lib/puma/events.rb:156:in `fire_on_stopped!'
    from gems/puma-5.6.5/lib/puma/launcher.rb:393:in `graceful_stop'
    from gems/puma-5.6.5/lib/puma/launcher.rb:488:in `block in setup_signals'
   ...

Looking at the code it seems to me that a & is missing in yabeda_prometheus.rb:

      events.on_stopped do
        unless server&.shutting_down?
          logger.log "* Stopping #{banner}"
          server.stop(true)
        end
      end

It looks like that when the app is stopped before server got a chance to run, this exception may occur.

If the server is not shutting down, the block is executed, and server.stop(true) is called. When server is nil I can imagine this error occurs. Perhaps a check like if server && !server.shutting_down? would be more appropriate here.

Envek commented 1 year ago

Thanks for reporting and sorry for the late reply!

Fixed in #27 (thanks to @ollym) and released in 0.7.1