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

Privatize binder listeners #1958

Merged
merged 1 commit into from Sep 11, 2019
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
19 changes: 18 additions & 1 deletion lib/puma/binder.rb
Expand Up @@ -42,7 +42,7 @@ def initialize(events)
@ios = []
end

attr_reader :listeners, :ios
attr_reader :ios

def env(sock)
@envs.fetch(sock, @proto_env)
Expand Down Expand Up @@ -413,5 +413,22 @@ def inherit_unix_listener(path, fd)
s
end

def close_listeners
@listeners.each do |l, io|
io.close
uri = URI.parse(l)
next unless uri.scheme == 'unix'
File.unlink("#{uri.host}#{uri.path}")
end
end

def redirects_for_restart
redirects = {:close_others => true}
@listeners.each_with_index do |(l, io), i|
ENV["PUMA_INHERIT_#{i}"] = "#{io.to_i}:#{l}"
redirects[io.to_i] = io.to_i
end
redirects
end
end
end
15 changes: 2 additions & 13 deletions lib/puma/launcher.rb
Expand Up @@ -217,12 +217,7 @@ def restart_args
end

def close_binder_listeners
@binder.listeners.each do |l, io|
io.close
uri = URI.parse(l)
next unless uri.scheme == 'unix'
File.unlink("#{uri.host}#{uri.path}")
end
@binder.close_listeners
end

private
Expand All @@ -246,15 +241,9 @@ def restart!
Dir.chdir(@restart_dir)
Kernel.exec(*argv)
else
redirects = {:close_others => true}
@binder.listeners.each_with_index do |(l, io), i|
ENV["PUMA_INHERIT_#{i}"] = "#{io.to_i}:#{l}"
redirects[io.to_i] = io.to_i
end

argv = restart_args
Dir.chdir(@restart_dir)
argv += [redirects]
argv += [@binder.redirects_for_restart]
Kernel.exec(*argv)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_binder.rb
Expand Up @@ -24,7 +24,7 @@ class TestBinder < TestBinderBase
def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
@binder.parse(["tcp://localhost:10001"], @events)

assert_equal [], @binder.listeners
assert_equal [], @binder.instance_variable_get(:@listeners)
end
end

Expand Down Expand Up @@ -54,7 +54,7 @@ def setup
def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
@binder.parse(["ssl://localhost:10002?key=#{@key}&cert=#{@cert}"], @events)

assert_equal [], @binder.listeners
assert_equal [], @binder.instance_variable_get(:@listeners)
end

def test_binder_parses_ssl_cipher_filter
Expand Down