unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: "Yeung, Jeffrey" <Jeffrey.Yeung@polycom.com>
To: Eric Wong <normalperson@yhbt.net>,
	unicorn list <mongrel-unicorn@rubyforge.org>
Subject: RE: Unicorn_rails ignores USR2 signal
Date: Fri, 30 Mar 2012 15:16:38 -0700	[thread overview]
Message-ID: <E8D9E7CCC2621343A0A3BB45E8DEDFA91C688BD14D@CRPMBOXPRD04.polycom.com> (raw)
In-Reply-To: <20120320195748.GA1187@dcvr.yhbt.net>

I have little to report, unfortunately.  I still have not identified what is trapping USR2 in my application, if something is indeed doing that.

I've attempted to do a bit more investigation work in my spare time this week, and the results are still rather mysterious.

First, I applied your patch to http_server.rb that you suggested in this thread back on March 9th (quoted below), which re-overrides the signal handlers in build_app!().  The patch did work.  Okay, that seems to reconfirm that the app is doing something with the USR2 signal handler...

Then I modified the master_siginit() method a bit further to provide more info:
  def master_siginit
    QUEUE_SIGS.each { |sig|
      old_handler = trap(sig) { SIG_QUEUE << sig; awaken_master }
      logger.info("old handler for #{sig.to_s}: #{old_handler.inspect}")
    }
    trap(:CHLD) { awaken_master }
  end

And the output was a bit surprising.  Here is the Unicorn stderr log when starting up the service.  master_siginit() is called twice, as expected...

I, [2012-03-30T14:57:51.301839 #15828]  INFO -- : listening on addr=0.0.0.0:8080 fd=3
I, [2012-03-30T14:57:51.302341 #15828]  INFO -- : old handler for WINCH: nil
I, [2012-03-30T14:57:51.302435 #15828]  INFO -- : old handler for QUIT: "DEFAULT"
I, [2012-03-30T14:57:51.302505 #15828]  INFO -- : old handler for INT: "DEFAULT"
I, [2012-03-30T14:57:51.302573 #15828]  INFO -- : old handler for TERM: "DEFAULT"
I, [2012-03-30T14:57:51.302641 #15828]  INFO -- : old handler for USR1: "DEFAULT"
I, [2012-03-30T14:57:51.302709 #15828]  INFO -- : old handler for USR2: "DEFAULT"
I, [2012-03-30T14:57:51.302786 #15828]  INFO -- : old handler for HUP: "DEFAULT"
I, [2012-03-30T14:57:51.302853 #15828]  INFO -- : old handler for TTIN: nil
I, [2012-03-30T14:57:51.302917 #15828]  INFO -- : old handler for TTOU: nil
I, [2012-03-30T14:57:51.303502 #15828]  INFO -- : Refreshing Gem list
old handler for WINCH: #<Proc:0x00000002d97488@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for QUIT: #<Proc:0x00000002d97098@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for INT: #<Proc:0x00000002d96c70@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for TERM: #<Proc:0x00000002d96848@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for USR1: #<Proc:0x00000002d96420@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for USR2: #<Proc:0x00000002d95ff8@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for HUP: #<Proc:0x00000002d95bd0@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for TTIN: #<Proc:0x00000002d957a8@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
old handler for TTOU: #<Proc:0x00000002d953b8@/usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:745>
master process ready
worker=0 ready

Which to me, looks like the USR2 handler was unchanged in the second master_siginit() call.  Yet, if I remove that second master_siginit() call from there, USR2 ceases to work.  :S

-Jeff

-----Original Message-----
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index 7d2c623..1b9d693 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -128,8 +128,7 @@ class Unicorn::HttpServer
     # setup signal handlers before writing pid file in case people get
     # trigger happy and send signals as soon as the pid file exists.
     # Note that signals don't actually get handled until the #join method
-    QUEUE_SIGS.each { |sig| trap(sig) { SIG_QUEUE << sig; awaken_master } }
-    trap(:CHLD) { awaken_master }
+    master_siginit
     self.pid = config[:pid]
 
     self.master_pid = $$
@@ -689,6 +688,9 @@ class Unicorn::HttpServer
         Gem.refresh
       end
       self.app = app.call
+
+      # override signal handlers the app may have set
+      master_siginit if preload_app
     end
   end
 
@@ -736,4 +738,9 @@ class Unicorn::HttpServer
     config_listeners.each { |addr| listen(addr) }
     raise ArgumentError, "no listeners" if LISTENERS.empty?
   end
+
+  def master_siginit
+    QUEUE_SIGS.each { |sig| trap(sig) { SIG_QUEUE << sig; awaken_master } }
+    trap(:CHLD) { awaken_master }
+  end
 end
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

  parent reply	other threads:[~2012-03-30 22:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-09 21:48 Unicorn_rails ignores USR2 signal Yeung, Jeffrey
2012-03-09 22:24 ` Eric Wong
2012-03-09 22:39   ` Yeung, Jeffrey
2012-03-10  0:02     ` Eric Wong
2012-03-10  1:07       ` Yeung, Jeffrey
2012-03-10  1:30         ` Eric Wong
2012-03-12 21:21           ` Eric Wong
2012-03-12 22:39             ` Yeung, Jeffrey
2012-03-12 22:44               ` Eric Wong
2012-03-20 19:57                 ` Eric Wong
2012-03-20 23:09                   ` Yeung, Jeffrey
2012-03-21  2:27                     ` Devin Ben-Hur
2012-03-30 22:16                   ` Yeung, Jeffrey [this message]
2012-03-30 22:51                     ` Alex Sharp
2013-05-08 18:15                       ` Ryan Jones (RyanonRails)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E8D9E7CCC2621343A0A3BB45E8DEDFA91C688BD14D@CRPMBOXPRD04.polycom.com \
    --to=jeffrey.yeung@polycom.com \
    --cc=mongrel-unicorn@rubyforge.org \
    --cc=normalperson@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).