diff options
author | Eric Wong <e@80x24.org> | 2013-10-30 18:32:53 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-31 05:04:30 +0000 |
commit | 3741b945dcaf2e432f9e0088b4553d17f5c68f2b (patch) | |
tree | 716e849598eb744e488b1de68309b92c817a0703 /lib/yahns/server.rb | |
parent | bfe699496ced8f73f659da0f0857fda614fb40b6 (diff) | |
download | yahns-3741b945dcaf2e432f9e0088b4553d17f5c68f2b.tar.gz |
Otherwise, the server may stay running forever if a client chooses to stay forever (and there is no FD pressure).
Diffstat (limited to 'lib/yahns/server.rb')
-rw-r--r-- | lib/yahns/server.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb index 4bd523f..6439918 100644 --- a/lib/yahns/server.rb +++ b/lib/yahns/server.rb @@ -12,12 +12,14 @@ class Yahns::Server # :nodoc: attr_accessor :logger attr_writer :user attr_writer :worker_processes + attr_writer :shutdown_timeout attr_writer :worker_atfork_prepare attr_writer :worker_atfork_parent attr_writer :worker_atfork_child include Yahns::SocketHelper def initialize(config) + @shutdown_timeout = nil @reexec_pid = 0 @daemon_pipe = nil # writable IO or true @config = config @@ -339,6 +341,8 @@ class Yahns::Server # :nodoc: # spin up applications (which are preload: false) @config.app_ctx.each(&:after_fork_init) + @shutdown_timeout ||= @config.app_ctx.map(&:client_timeout).max + # spin up acceptor threads, clients flow into worker queues after this @listeners.each do |l| opts = sock_opts(l) @@ -413,6 +417,15 @@ class Yahns::Server # :nodoc: alive end + def dropping(fdmap) + if drop_acceptors[0] || fdmap.size > 0 + fdmap.desperate_expire_for(nil, @shutdown_timeout) + true + else + false + end + end + # single-threaded only, this is overriden if @worker_processes is non-nil def join daemon_ready @@ -422,7 +435,7 @@ class Yahns::Server # :nodoc: alive = sp_sig_handle(alive) rescue => e Yahns::Log.exception(@logger, "main loop", e) - end while alive || drop_acceptors[0] || fdmap.size > 0 + end while alive || dropping(fdmap) unlink_pid_safe(@pid) if @pid ensure quit_finish |