Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/puma/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ def wait_workers
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
Expand Down
1 change: 1 addition & 0 deletions lib/puma/cluster/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def run

Signal.trap "SIGTERM" do
@worker_write << "e#{Process.pid}\n" rescue nil
restart_server.clear
server.stop
restart_server << false
end
Expand Down
11 changes: 11 additions & 0 deletions test/test_puma_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1150,4 +1150,15 @@ def test_run_stop_thread_safety
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