defunkt/resque — pull request #672 by kjwierenga (2012-09-23 12:38:04+00:00)
Title: Don't invoke :before_fork and :after_fork hooks when not forking - fixes fd leak when used with NewRelic

On platforms that don't support `Kernel.fork` or in situations where you explicitly don't want to fork (by setting `worker.cant_fork = true` explicitly) we musn't invoke the `:before_fork` hooks and the `:after_fork` hooks.

In my case setting `worker.cant_fork = true` was causing a file-descriptor leak and gradual CPU usage increase in combination with the NewRelic agent. The NewRelic agent creates a pipe with the (to be created) child process in its `Resque.before_fork` hook for each job performed. But because we prevented the proces from forking (by settings `worker.cant_fork = true`) these pipe would never be closed (since closing the pipes is done in the exit handling of the child process).

This patch the 'normal' case where we do fork unchanged. It makes sure that `before_fork` and `after_fork` hooks are only called when we know for sure that we will fork a worker.