mperham/sidekiq — pull request #207 by dazuma (2012-05-21 18:30:20+00:00)
Title: Gracefully handle receipt of multiple termination signals

This is a fix for an issue I came across yesterday when deploying a sidekiq worker as a daemon.

The issue is that when you send a SIGTERM or SIGINT to a running worker, it initiates shutdown by raising an Interrupt in the main thread. The shutdown process takes a finite amount of time because it waits for the manager to shut down, and then Celluloid registers an at\_exit process that does its own cleanup of running actors. If another signal is received during that cleanup process, the cleanup itself is interrupted by an exception, and this causes the whole system to go crazy. In my case, the second signal was received during Celluloid's at\_exit cleanup, and, on Mac OS Lion, this (for reasons I don't care to understand fully) caused the process to spin at 100% cpu until you kill -9 it.

This patch simply ensures that at most one Interrupt exception is raised as a result of receiving a termination signal.