From: Eric Wong <normalperson@yhbt.net>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: Strange quit behavior
Date: Wed, 17 Aug 2011 13:13:23 -0700 [thread overview]
Message-ID: <20110817201323.GA24581@dcvr.yhbt.net> (raw)
In-Reply-To: <20110817092252.GA7186@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> wrote:
> Below is a proposed patch (to unicorn.git) which may help debug issues
> in the signal -> handler master path (but only once it enters the Ruby
> runtime). I'm a hesitant to commit it since it worthless if the Ruby
> process is stuck because of some bad C extension. That's the most
> common cause of stuck/unresponsive processes I've seen.
I think that was a bad patch, adding signal handler debugging at the
Ruby layer leads to the false assumption that interpreter/VM is in a
good state. If you need to debug signal handlers, something is already
broken and tracing syscalls is the most reliable way to go.
Ruby (and any other high-level language) signal handling is not
straight forward[1].
Here's how things work in Matz Ruby 1.9.x[2]:
you C timer thread Ruby Thread(s)
-------------------------------------------------------------------
traps signals ignores most signals
sleeps runs Ruby...
kill -USR2 ...
receives signal (async)
runs (system) sighandler[1]
wakes up from sleep
signals Ruby Thread(s)
*hopefully wakes up*
runs Ruby sighandler
The "*hopefully wakes up*" part is the part most likely to fail
as a result of a bad C extension or Ruby bug.
PS. In Ruby 1.9.3, timer thread uses the "self-pipe" sighandler
implementation that the unicorn master process always used.
This allows Ruby 1.9.3 to conserve power on idle processes.
In 1.9.2, the timer thread signal handler just polls in
10ms intervals to check if any signals were received.
This is why "strace -f" is noisy and I recommend "-e '!futex'"
for 1.9.2.
PPS. Unicorn still uses the "self-pipe" signal handler in Ruby-land
because Ruby signal handlers are reentrant so must execute
reentrant-safe code. So without the self-pipe to serialize
the signal handler dispatch, the Ruby signal handler execution
can nest and overlap execution with itself. This means if USR2
is sent multiple times in short succession, you could spawn
multiple new unicorn masters
[1] - See "man 7 signal" in Linux manpages or POSIX specs for the
small list of safe functions that may be called in system-level
sighandlers. Ruby-level signal handlers can't run inside
system-level signal handlers for this reason.
[2] - I think any high-level language that implements signal handlers
AND native threads must do something similar. The only valid
variation I can think of is to execute the high-level language
code inside the timer thread, but that requires the coders of
the high-level language to have thread-safety (not just
reentrancy) in mind when writing signal handlers even if the
rest of their code uses no threads.
--
Eric Wong
_______________________________________________
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
next prev parent reply other threads:[~2011-08-17 20:16 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 20:09 Strange quit behavior James Cox
2011-08-02 20:34 ` Alex Sharp
2011-08-02 21:54 ` Eric Wong
2011-08-05 4:09 ` Alex Sharp
2011-08-05 4:12 ` Alex Sharp
2011-08-05 8:07 ` Eric Wong
2011-08-17 4:26 ` Alex Sharp
2011-08-17 9:22 ` Eric Wong
2011-08-17 20:13 ` Eric Wong [this message]
2011-08-18 23:13 ` Alex Sharp
2011-08-19 1:53 ` Eric Wong
2011-08-19 9:42 ` Alex Sharp
2011-08-19 16:51 ` Eric Wong
2011-08-23 2:59 ` Alex Sharp
2011-08-23 7:12 ` Eric Wong
2011-08-23 16:49 ` Alex Sharp
2011-08-23 20:23 ` Eric Wong
2011-08-31 0:33 ` Eric Wong
2011-09-01 18:45 ` Alex Sharp
2011-09-01 19:46 ` Eric Wong
2011-09-01 19:57 ` Alex Sharp
2011-09-01 20:26 ` Eric Wong
2011-08-02 20:45 ` cliftonk
2011-08-02 21:53 ` Eric Wong
2011-08-02 22:46 ` James Cox
2011-08-02 23:08 ` Eric Wong
2011-08-02 23:49 ` Alex Sharp
2011-08-03 0:34 ` Eric Wong
2011-08-03 1:36 ` Eric Wong
2011-08-19 22:18 ` Eric Wong
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=20110817201323.GA24581@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=mongrel-unicorn@rubyforge.org \
/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).