From 3eb994e87d7c9a82887e2a68b134b851215c8f75 Mon Sep 17 00:00:00 2001 From: Vitalii Khustochka Date: Sun, 20 Feb 2022 08:27:57 -0600 Subject: [PATCH] Do not remove pre-existing socket after USR2+TERM (#2816) (#2817) The issue was that inherited socket was added to the @unix_paths list even if it was pre-existing. Test added. Closed #2816. --- lib/puma/binder.rb | 2 +- test/test_integration_cluster.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index 300ece14da..dd4556d196 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -189,7 +189,7 @@ def parse(binds, logger, log_msg = 'Listening') end if fd = @inherited_fds.delete(str) - @unix_paths << path unless abstract + @unix_paths << path unless abstract || File.exist?(path) io = inherit_unix_listener path, fd logger.log "* Inherited #{str}" elsif sock = @activated_sockets.delete([ :unix, path ]) || diff --git a/test/test_integration_cluster.rb b/test/test_integration_cluster.rb index 979765f067..dd0f29171e 100644 --- a/test/test_integration_cluster.rb +++ b/test/test_integration_cluster.rb @@ -43,6 +43,26 @@ def test_pre_existing_unix end end + def test_pre_existing_unix_stop_after_restart + skip_unless :unix + + File.open(@bind_path, mode: 'wb') { |f| f.puts 'pre existing' } + + cli_server "-w #{workers} -q test/rackup/sleep_step.ru", unix: :unix + connection = connect(nil, unix: true) + restart_server connection + + connect(nil, unix: true) + stop_server + + assert File.exist?(@bind_path) + + ensure + if UNIX_SKT_EXIST + File.unlink @bind_path if File.exist? @bind_path + end + end + def test_siginfo_thread_print skip_unless_signal_exist? :INFO