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

Replace use of Process.getpgid which does not behave as intended on all platforms #1110

Merged
merged 2 commits into from Dec 12, 2016
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
52 changes: 26 additions & 26 deletions lib/puma/control_cli.rb
Expand Up @@ -179,39 +179,39 @@ def send_signal
end

begin
Process.getpgid @pid
rescue SystemCallError
if @command == "restart"
start
else
raise "No pid '#{@pid}' found"
end
end

case @command
when "restart"
Process.kill "SIGUSR2", @pid
case @command
when "restart"
Process.kill "SIGUSR2", @pid

when "halt"
Process.kill "QUIT", @pid
when "halt"
Process.kill "QUIT", @pid

when "stop"
Process.kill "SIGTERM", @pid
when "stop"
Process.kill "SIGTERM", @pid

when "stats"
puts "Stats not available via pid only"
return
when "stats"
puts "Stats not available via pid only"
return

when "reload-worker-directory"
puts "reload-worker-directory not available via pid only"
return
when "reload-worker-directory"
puts "reload-worker-directory not available via pid only"
return

when "phased-restart"
Process.kill "SIGUSR1", @pid
when "phased-restart"
Process.kill "SIGUSR1", @pid

else
message "Puma is started"
return
else
message "Puma is started"
return
end

rescue SystemCallError
if @command == "restart"
start
else
raise "No pid '#{@pid}' found"
end
end

message "Command #{@command} sent success"
Expand Down
25 changes: 24 additions & 1 deletion test/test_integration.rb
Expand Up @@ -155,7 +155,7 @@ def test_phased_restart_via_pumactl
@events.stdout.rewind
log = @events.stdout.readlines.join("")
assert_match(/TERM sent/, log)
assert_match(/Worker \d \(pid: \d+\) booted, phase: 1/, log)
assert_match(/- Worker \d \(pid: \d+\) booted, phase: 1/, log)

# Stop
ccli = Puma::ControlCLI.new %W!-S #{@state_path} stop!, sout
Expand All @@ -164,6 +164,29 @@ def test_phased_restart_via_pumactl
assert_kind_of Thread, t.join(5), "server didn't stop"
end

def test_kill_unknown_via_pumactl
if Puma.jruby? || Puma.windows?
assert true
return
end

# we run ls to get a 'safe' pid to pass off as puma in cli stop
# do not want to accidently kill a valid other process
io = IO.popen("ls")
safe_pid = io.pid
Process.wait safe_pid

sout = StringIO.new

e = assert_raises SystemExit do
ccli = Puma::ControlCLI.new %W!-p #{safe_pid} stop!, sout
ccli.run
end
sout.rewind
assert_match(/No pid '\d+' found/, sout.readlines.join(""))
assert_equal(1, e.status)
end

def test_restart_closes_keepalive_sockets
server("-q test/hello.ru")

Expand Down