Method: Unicorn::Configurator#timeout

Defined in:
lib/unicorn/configurator.rb

#timeout(seconds) ⇒ Object

sets the timeout of worker processes to seconds. Workers handling the request/app.call/response cycle taking longer than this time period will be forcibly killed (via SIGKILL). This timeout is enforced by the master process itself and not subject to the scheduling limitations by the worker process. Due the low-complexity, low-overhead implementation, timeouts of less than 3.0 seconds can be considered inaccurate and unsafe.

For running Unicorn behind nginx, it is recommended to set “fail_timeout=0” for in your nginx configuration like this to have nginx always retry backends that may have had workers SIGKILL-ed due to timeouts.

upstream unicorn_backend {
  # for UNIX domain socket setups:
  server unix:/path/to/.unicorn.sock fail_timeout=0;

  # for TCP setups
  server 192.168.0.7:8080 fail_timeout=0;
  server 192.168.0.8:8080 fail_timeout=0;
  server 192.168.0.9:8080 fail_timeout=0;
}

See nginx.org/en/docs/http/ngx_http_upstream_module.html for more details on nginx upstream configuration.



196
197
198
199
200
201
# File 'lib/unicorn/configurator.rb', line 196

def timeout(seconds)
  set_int(:timeout, seconds, 3)
  # POSIX says 31 days is the smallest allowed maximum timeout for select()
  max = 30 * 60 * 60 * 24
  set[:timeout] = seconds > max ? max : seconds
end