sigwinch and screen

Brian P O'Rourke bpo at
Wed Sep 14 10:29:05 EDT 2011

(my apologies if this gets posted twice - don't think my earlier mail
went through)


I'm running unicorn within screen and have run into some trouble.
Unicorn tries to ignore sigwinch when it's not daemonized.
Unfortunately the check for daemonization fails when unicorn is exec'd
from a process that already has a pgrp.

You can simulate this problem from *within* a screen session with
something like this:

    screen sleep 5 && screen bundle exec unicorn -c unicorn.conf

sigwinch will be sent to the second screen session the first time you
change to it. This doesn't happen unless you launch at least two
screens in rapid succession, for reasons that escape me so far -
haven't dug into that part much yet.

It seems to me that this is a problem, and is occurring because
Unicorn's check for daemonization is "is init my parent or is my group
different from my pid?", which isn't necessarily the same as checking
whether daemonization has happened.

Here is the patch I would like to see applied:

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index ae0e175..65880d4 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -282,7 +282,7 @@ class Unicorn::HttpServer
       when :USR2 # exec binary, stay alive in case something went wrong
       when :WINCH
-        if Process.ppid == 1 || Process.getpgrp != $$
+        if Unicorn::Configurator::RACKUP[:daemonized]
           respawn = false
  "gracefully stopping all workers"

More information about the mongrel-unicorn mailing list