diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index f2165f7474..d0b122e782 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -50,14 +50,6 @@ def env(sock) def close @ios.each { |i| i.close } - @unix_paths.each do |i| - # Errno::ENOENT is intermittently raised - begin - unix_socket = UNIXSocket.new i - unix_socket.close - rescue Errno::ENOENT - end - end end def import_from_env diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 24f4ea5f85..5bc22d83f3 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -68,7 +68,7 @@ def initialize(idx, pid, phase, options) @pid = pid @phase = phase @stage = :started - @signal = "TERM" + @signal = :TERM @options = options @first_term_sent = nil @started_at = Time.now @@ -108,7 +108,7 @@ def ping_timeout?(which) def term begin if @first_term_sent && (Time.now - @first_term_sent) > @options[:worker_shutdown_timeout] - @signal = "KILL" + @signal = :KILL else @term ||= true @first_term_sent ||= Time.now @@ -119,12 +119,12 @@ def term end def kill - Process.kill "KILL", @pid + Process.kill :KILL, @pid rescue Errno::ESRCH end def hup - Process.kill "HUP", @pid + Process.kill :HUP, @pid rescue Errno::ESRCH end end @@ -220,8 +220,10 @@ def check_workers(force=false) log "- Stopping #{w.pid} for phased upgrade..." end - w.term - log "- #{w.signal} sent to #{w.pid}..." + unless w.term? + w.term + log "- #{w.signal} sent to #{w.pid}..." + end end end end @@ -270,6 +272,7 @@ def worker(index, master) server = start_server Signal.trap "SIGTERM" do + @worker_write << "e#{Process.pid}\n" rescue nil server.stop end @@ -501,8 +504,10 @@ def run w.boot! log "- Worker #{w.index} (pid: #{pid}) booted, phase: #{w.phase}" force_check = true + when "e" + w.instance_variable_set :@term, true when "t" - w.term + w.term unless w.term? force_check = true when "p" w.ping!(result.sub(/^\d+/,'').chomp) diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index da9bce2573..ee21a0761f 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -217,11 +217,12 @@ def restart_args end def close_binder_listeners - @binder.listeners.each do |l, io| - io.close + # close binder listeners as fast as possible, so separate loop + @binder.listeners.each { |_, io| io.close } + @binder.listeners.each do |l, _| uri = URI.parse(l) next unless uri.scheme == 'unix' - File.unlink("#{uri.host}#{uri.path}") + File.unlink "#{uri.host}#{uri.path}" end end