diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 0d7c12bd69..dc832850cc 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -560,9 +560,11 @@ def wait_workers @workers.reject! do |w| next false if w.pid.nil? begin - # When `fork_worker` is enabled, some worker may not be direct children, but grand children. - # Because of this they won't be reaped by `Process.wait2(-1)`, so we need to check them individually) - if reaped_children.delete(w.pid) || (@options[:fork_worker] && Process.wait(w.pid, Process::WNOHANG)) + # We may need to check the PID individually because: + # 1. On some environments running as PID 1, `Process.wait2(-1)` might not return anything. + # 2. When `fork_worker` is enabled, some worker may not be direct children, but grand children. + # Because of this they won't be reaped by `Process.wait2(-1)`. + if reaped_children.delete(w.pid) || Process.wait(w.pid, Process::WNOHANG) true else w.term if w.term?