Timeout callback

Eric Wong normalperson at yhbt.net
Sun Sep 25 21:42:59 EDT 2011

Alex Sharp <ajsharp at gmail.com> wrote:
>  Would there be any support for a worker-level timeout callback, for
>  workers that get killed by the master process for violating the
>  Unicorn::Configurator.timeout setting?

Something like this /cannot/ be done right.  The unicorn timeout uses
SIGKILL because SIGKILL is a last resort and not
catchable/blockable/trappable in user space.  (SIGSTOP is in the same
boat as SIGKILL).

> I'm thinking the method could be on the Unicorn::Configurator class,
> something like ".at_timeout_exit". My thinking here is I want to be
> able to invoke caller() and get a backtrace to figure out the code
> that's resulting in timeouts. 

Getting a backtrace relies on Ruby being in a runnable state.
If user space (and Ruby) is capable of accepting non-SIGKILL/SIGSTOP,
you could already be using something along the lines of the Timeout
module in Ruby stdlib, SystemTimeout, or the Rainbows::ThreadTimeout

In other words, you can already use an application-level timeout
(even around the entire app dispatch) if you could get a backtrace.

More information about the mongrel-unicorn mailing list