diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index b102af2948..32876af601 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -44,19 +44,14 @@ def initialize(events) attr_reader :listeners, :ios + # TODO: Removing listeners should clean up @envs too def env(sock) @envs.fetch(sock, @proto_env) end def close - @ios.each { |i| i.close } - @unix_paths.each do |i| - # Errno::ENOENT is intermittently raised - begin - File.unlink i - rescue Errno::ENOENT - end - end + @ios.each { |i| i.close && @ios.delete(i) } + @unix_paths.each { |i| File.unlink(i) && @unix_paths.delete(i) } end def import_from_env diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index d3da53d6a8..ccc672b4ce 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -381,6 +381,7 @@ def setup_signals log "Early termination of worker" exit! 0 else + # TODO: replace with binder.close? @launcher.close_binder_listeners stop_workers diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 642fea9f64..cbc097be16 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -74,7 +74,6 @@ def initialize(app, events=Events.stdio, options={}) @first_data_timeout = options.fetch(:first_data_timeout, FIRST_DATA_TIMEOUT) @binder = Binder.new(events) - @own_binder = true @leak_stack_on_error = true @@ -97,7 +96,6 @@ def initialize(app, events=Events.stdio, options={}) def inherit_binder(bind) @binder = bind - @own_binder = false end def tcp_mode! @@ -271,6 +269,8 @@ def handle_servers_lopez_mode rescue IOError # no biggy end + + @binder.close if @status != :restart end @events.fire :state, :done @@ -417,8 +417,8 @@ def handle_servers end @events.fire :state, @status - graceful_shutdown if @status == :stop || @status == :restart + if queue_requests @reactor.clear! @reactor.shutdown @@ -430,9 +430,7 @@ def handle_servers @check.close @notify.close - if @status != :restart and @own_binder - @binder.close - end + @binder.close if @status != :restart end @events.fire :state, :done @@ -952,6 +950,8 @@ def graceful_shutdown @events.debug "Drained #{count} additional connections." end + @binder.close if @status != :restart + if @thread_pool if timeout = @options[:force_shutdown_after] @thread_pool.shutdown timeout.to_i diff --git a/test/test_integration.rb b/test/test_integration.rb index 8dbe79625f..3ce5fa3de5 100644 --- a/test/test_integration.rb +++ b/test/test_integration.rb @@ -193,12 +193,12 @@ def test_phased_restart_via_pumactl done = true end end - # Stop + + assert File.exist? @bind_path ccli = Puma::ControlCLI.new ["-S", @state_path, "stop"], sout ccli.run assert_kind_of Thread, t.join, "server didn't stop" - assert File.exist? @bind_path end def test_kill_unknown_via_pumactl