zombocom / puma_worker_killer

Automatically restart Puma cluster workers based on max RAM available
747 stars 77 forks source link

fix: Avoid crashing if not in cluster mode #103

Open jcw- opened 1 year ago

jcw- commented 1 year ago

If PumaWorkerKiller is enabled, but Puma isn't in cluster mode (no workers), after roughly six hours, it crashes:

#<Thread:0x00007fdcbc998ef0 /Users/jcw/.rvm/gems/ruby-2.7.6/gems/puma_worker_killer-0.3.1/lib/puma_worker_killer/auto_reap.rb:14 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    4: from /Users/jcw/.rvm/gems/ruby-2.7.6/gems/puma_worker_killer-0.3.1/lib/puma_worker_killer/auto_reap.rb:17:in `block in start'
    3: from /Users/jcw/.rvm/gems/ruby-2.7.6/gems/puma_worker_killer-0.3.1/lib/puma_worker_killer/rolling_restart.rb:17:in `reap'
    2: from /Users/jcw/.rvm/gems/ruby-2.7.6/gems/puma_worker_killer-0.3.1/lib/puma_worker_killer/rolling_restart.rb:12:in `get_total_memory'
    1: from /Users/jcw/.rvm/gems/ruby-2.7.6/gems/puma_worker_killer-0.3.1/lib/puma_worker_killer/puma_memory.rb:53:in `get_total'
/Users/jcw/.rvm/gems/ruby-2.7.6/gems/puma_worker_killer-0.3.1/lib/puma_worker_killer/puma_memory.rb:75:in `set_workers': undefined method `each' for nil:NilClass (NoMethodError)

While it's true that this plugin doesn't make sense to run unless there's workers to monitor, in case someone does, this PR fixes the crash.

schneems commented 1 month ago

Sorry for the extreme delay here. I think this is a good idea. It conflicts with code, could you rebase it against main?