1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Fix hang on shutdown in test_refork [changelog skip] (#2442)

* Prevent server from starting if worker receives TERM signal
If a worker receives a `TERM` signal before the server has started,
prevent it from starting at all by clearing `restart_server`.

* Send TERM to fork_worker child processes in Cluster#wait_workers
When `fork_worker` is used, the call to `Process.wait` in `wait_workers`
returns `ECHILD` for forked workers.
Add a call to `w.term` in the rescue clause to match the behavior when
`fork_worker` is not used, ensuring workers shut down properly.

* Add test_command_ignored_before_run
Unit test clarifying behavior of commands sent before Server#run is called.
This commit is contained in:
Will Jordan 2020-10-22 12:54:15 -07:00 committed by GitHub
parent cd158f7651
commit c1a98f8f22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -479,7 +479,9 @@ module Puma
rescue Errno::ECHILD
begin
Process.kill(0, w.pid)
false # child still alive, but has another parent
# child still alive but has another parent (e.g., using fork_worker)
w.term if w.term?
false
rescue Errno::ESRCH, Errno::EPERM
true # child is already terminated
end

View file

@ -91,6 +91,7 @@ module Puma
Signal.trap "SIGTERM" do
@worker_write << "e#{Process.pid}\n" rescue nil
restart_server.clear
server.stop
restart_server << false
end

View file

@ -1150,4 +1150,15 @@ EOF
assert thread.join(1)
end
end
def test_command_ignored_before_run
@server.stop # ignored
@server.run
@server.halt
done = Queue.new
@server.events.register(:state) do |state|
done << @server.instance_variable_get(:@status) if state == :done
end
assert_equal :halt, done.pop
end
end