Skip to content

Commit

Permalink
Updates binder.rb, cluster.rb, launcher.rb
Browse files Browse the repository at this point in the history
1. binder.rb   Add PR puma#1886

2. cluster.rb  Add PR puma#1952, additional minor changes

3. launcher.rb #close_binder_listeners close io's as fast as possible
  • Loading branch information
MSP-Greg committed Sep 9, 2019
1 parent 8a58dd3 commit 4256bc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
8 changes: 0 additions & 8 deletions lib/puma/binder.rb
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions lib/puma/cluster.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lib/puma/launcher.rb
Expand Up @@ -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

Expand Down

0 comments on commit 4256bc0

Please sign in to comment.