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

Deal with pipes closing while stopping. Fixes #270

The bug was that the SIGCHLD handler would fire after the ensure block
that closed the pipe. We can just ignore write errors on that pipe.
This commit is contained in:
Evan Phoenix 2013-06-01 14:44:26 -07:00
parent 9e63281097
commit 10b6667403

View file

@ -552,7 +552,12 @@ module Puma
server.stop
end
@worker_write << "b#{Process.pid}\n"
begin
@worker_write << "b#{Process.pid}\n"
rescue SystemCallError, IOError
STDERR.puts "Master seems to have exitted, exitting."
return
end
server.run.join
@ -648,6 +653,13 @@ module Puma
end
end
def wakeup!
begin
@wakeup.write "!" unless @wakeup.closed?
rescue SystemCallError, IOError
end
end
def run_cluster
log "Puma #{Puma::Const::PUMA_VERSION} starting in cluster mode..."
log "* Process workers: #{@options[:workers]}"
@ -661,10 +673,10 @@ module Puma
exit 1
end
read, write = Puma::Util.pipe
read, @wakeup = Puma::Util.pipe
Signal.trap "SIGCHLD" do
write.write "!"
wakeup!
end
stop = false
@ -673,7 +685,7 @@ module Puma
Signal.trap "SIGUSR2" do
@restart = true
stop = true
write.write "!"
wakeup!
end
rescue Exception
end
@ -690,7 +702,7 @@ module Puma
exit! 0
else
stop = true
write.write "!"
wakeup!
end
end
rescue Exception
@ -701,7 +713,7 @@ module Puma
begin
Signal.trap "SIGUSR1" do
phased_restart = true
write.write "!"
wakeup!
end
rescue Exception
end
@ -725,12 +737,12 @@ module Puma
write_state
@master_read, @worker_write = read, write
@master_read, @worker_write = read, @wakeup
spawn_workers
Signal.trap "SIGINT" do
stop = true
write.write "!"
wakeup!
end
begin
@ -771,7 +783,7 @@ module Puma
@check_pipe.close
@suicide_pipe.close
read.close
write.close
@wakeup.close
end
if @restart