From cfc7b0f025ef4c02f4a224525e80bb5793c90eca Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Tue, 11 Feb 2020 11:05:06 -0800 Subject: [PATCH] Ensure control server Unix socket is closed on shutdown Remove Binder#close_unix_paths --- lib/puma/binder.rb | 4 ---- lib/puma/launcher.rb | 3 ++- lib/puma/runner.rb | 4 ++++ test/test_binder.rb | 4 ++-- test/test_integration_pumactl.rb | 12 +++++++++++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index aa0e1d7e78..d36aaaaf00 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -369,10 +369,6 @@ def close_listeners end end - def close_unix_paths - @unix_paths.each { |up| File.unlink(up) if File.exist? up } - end - def redirects_for_restart redirects = {:close_others => true} @listeners.each_with_index do |(l, io), i| diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index 4b96588a57..f50ee7b0f0 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -184,7 +184,7 @@ def run when :exit # nothing end - @binder.close_unix_paths + close_binder_listeners unless @status == :restart end # Return which tcp port the launcher is using, if it's using TCP @@ -202,6 +202,7 @@ def restart_args end def close_binder_listeners + @runner.close_control_listeners @binder.close_listeners end diff --git a/lib/puma/runner.rb b/lib/puma/runner.rb index 078a26d760..4de9a6f213 100644 --- a/lib/puma/runner.rb +++ b/lib/puma/runner.rb @@ -68,6 +68,10 @@ def start_control @control = control end + def close_control_listeners + @control.binder.close_listeners if @control + end + def ruby_engine if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" "ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" diff --git a/test/test_binder.rb b/test/test_binder.rb index 7bd930946c..c16330703f 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -90,7 +90,7 @@ def test_pre_existing_unix refute_includes @binder.instance_variable_get(:@unix_paths), unix_path - @binder.close_unix_paths + @binder.close_listeners assert File.exist?(unix_path) @@ -150,7 +150,7 @@ def assert_parsing_logs_uri(order = [:unix, :tcp]) assert stdout.include?(prepared_paths[order[0]]), "\n#{stdout}\n" assert stdout.include?(prepared_paths[order[1]]), "\n#{stdout}\n" ensure - @binder.close_unix_paths if order.include?(:unix) && UNIX_SKT_EXIST + @binder.close_listeners if order.include?(:unix) && UNIX_SKT_EXIST end end diff --git a/test/test_integration_pumactl.rb b/test/test_integration_pumactl.rb index b7ae5f715f..e294bc3ab5 100644 --- a/test/test_integration_pumactl.rb +++ b/test/test_integration_pumactl.rb @@ -14,6 +14,8 @@ def setup def teardown super + refute File.exist?(@control_path), "Control path must be removed after stop" + ensure [@state_path, @control_path].each { |p| File.unlink(p) rescue nil } end @@ -30,10 +32,18 @@ def test_stop_tcp end def test_stop_unix + ctl_unix + end + + def test_halt_unix + ctl_unix 'halt' + end + + def ctl_unix(signal='stop') skip UNIX_SKT_MSG unless UNIX_SKT_EXIST cli_server "-q test/rackup/sleep.ru --control-url unix://#{@control_path} --control-token #{TOKEN} -S #{@state_path}", unix: true - cli_pumactl "stop", unix: true + cli_pumactl signal, unix: true _, status = Process.wait2(@pid) assert_equal 0, status