diff options
-rw-r--r-- | lib/unicorn.rb | 2 | ||||
-rw-r--r-- | lib/unicorn/http_server.rb | 13 | ||||
-rw-r--r-- | t/listener_names.ru | 4 | ||||
-rw-r--r-- | t/t0022-listener_names-preload_app.sh | 32 |
4 files changed, 49 insertions, 2 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index b882ce3..d96ff91 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -82,7 +82,7 @@ module Unicorn def self.listener_names Unicorn::HttpServer::LISTENERS.map do |io| Unicorn::SocketHelper.sock_name(io) - end + end + Unicorn::HttpServer::NEW_LISTENERS end def self.log_error(logger, prefix, exc) diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index 14a6f9a..13df55a 100644 --- a/lib/unicorn/http_server.rb +++ b/lib/unicorn/http_server.rb @@ -28,6 +28,9 @@ class Unicorn::HttpServer # all bound listener sockets LISTENERS = [] + # listeners we have yet to bind + NEW_LISTENERS = [] + # This hash maps PIDs to Workers WORKERS = {} @@ -134,6 +137,7 @@ class Unicorn::HttpServer self.master_pid = $$ build_app! if preload_app + bind_new_listeners! spawn_missing_workers self end @@ -738,7 +742,14 @@ class Unicorn::HttpServer @init_listeners << Unicorn::Const::DEFAULT_LISTEN START_CTX[:argv] << "-l#{Unicorn::Const::DEFAULT_LISTEN}" end - config_listeners.each { |addr| listen(addr) } + NEW_LISTENERS.replace(config_listeners) + end + + # call only after calling inherit_listeners! + # This binds any listeners we did NOT inherit from the parent + def bind_new_listeners! + NEW_LISTENERS.each { |addr| listen(addr) } raise ArgumentError, "no listeners" if LISTENERS.empty? + NEW_LISTENERS.clear end end diff --git a/t/listener_names.ru b/t/listener_names.ru new file mode 100644 index 0000000..edb4e6a --- /dev/null +++ b/t/listener_names.ru @@ -0,0 +1,4 @@ +use Rack::ContentLength +use Rack::ContentType, "text/plain" +names = Unicorn.listener_names.inspect # rely on preload_app=true +run(lambda { |_| [ 200, {}, [ names ] ] }) diff --git a/t/t0022-listener_names-preload_app.sh b/t/t0022-listener_names-preload_app.sh new file mode 100644 index 0000000..d07a26c --- /dev/null +++ b/t/t0022-listener_names-preload_app.sh @@ -0,0 +1,32 @@ +#!/bin/sh +. ./test-lib.sh + +# Raindrops::Middleware depends on Unicorn.listener_names, +# ensure we don't break Raindrops::Middleware when preload_app is true + +t_plan 4 "Unicorn.listener_names available with preload_app=true" + +t_begin "setup and startup" && { + unicorn_setup + echo preload_app true >> $unicorn_config + unicorn -E none -D listener_names.ru -c $unicorn_config + unicorn_wait_start +} + +t_begin "read listener names includes listener" && { + resp=$(curl -sSf http://$listen/) + ok=false + t_info "resp=$resp" + case $resp in + *\"$listen\"*) ok=true ;; + esac + $ok +} + +t_begin "killing succeeds" && { + kill $unicorn_pid +} + +t_begin "check stderr" && check_stderr + +t_done |