Permalink
Browse files

add "timeout_signal" configuration;

A signal that kill workers on timeout
  • Loading branch information...
issei-naruta
issei-naruta committed Feb 1, 2012
1 parent b6a154e commit d0b24198af57383d1c09f7be79c7e59c161bcfe5
Showing with 8 additions and 3 deletions.
  1. +5 −0 lib/unicorn/configurator.rb
  2. +3 −3 lib/unicorn/http_server.rb
@@ -32,6 +32,7 @@ class Unicorn::Configurator
# Default settings for Unicorn
DEFAULTS = {
:timeout => 60,
:timeout_signal => "KILL",
:logger => Logger.new($stderr),
:worker_processes => 1,
:after_fork => lambda { |server, worker|
@@ -193,6 +194,10 @@ def timeout(seconds)
set[:timeout] = seconds > max ? max : seconds
end
def timeout_signal(signal)
set[:timeout_signal] = signal
end
# sets the current number of worker_processes to +nr+. Each worker
# process will serve exactly one client at a time. You can
# increment or decrement this value at runtime by sending SIGTTIN
@@ -12,7 +12,7 @@
# See Unicorn::Configurator for information on how to configure \Unicorn.
class Unicorn::HttpServer
# :stopdoc:
attr_accessor :app, :request, :timeout, :worker_processes,
attr_accessor :app, :request, :timeout, :timeout_signal, :worker_processes,
:before_fork, :after_fork, :before_exec,
:listener_opts, :preload_app,
:reexec_pid, :orig_app, :init_listeners,
@@ -456,8 +456,8 @@ def murder_lazy_workers
end
next_sleep = 0
logger.error "worker=#{worker.nr} PID:#{wpid} timeout " \
"(#{diff}s > #{@timeout}s), killing"
kill_worker(:KILL, wpid) # take no prisoners for timeout violations
"(#{diff}s > #{@timeout}s), killing(#{@timeout_signal})"
kill_worker(@timeout_signal, wpid) # take no prisoners for timeout violations

This comment has been minimized.

@kuboon

kuboon Mar 20, 2014

この後 :KILL も送らないと、本当に hangup した場合などに殺せなくなりませんか?

This comment has been minimized.

@mirakui

mirakui Mar 20, 2014

Member

はい、そのとおりです。
なので master から worker へはこの timeout_signal として INT などを送らせておいて、それでしばらくしても死んでなかったら、別のスクリプトで定期的にそういう worker に KILL を送るっていう運用をしています。

This comment has been minimized.

@kuboon
end
next_sleep <= 0 ? 1 : next_sleep
end

0 comments on commit d0b2419

Please sign in to comment.