unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: pid file deleted briefly when doing hot restart
Date: Tue, 27 Nov 2012 21:51:46 +0000	[thread overview]
Message-ID: <20121127215146.GA23452@dcvr.yhbt.net> (raw)
In-Reply-To: <50B4E63C.9000305@gentoo.org>

Petteri Räty <betelgeuse@gentoo.org> wrote:
> On 27.11.2012 4.02, Eric Wong wrote:
> > Petteri Räty <betelgeuse@gentoo.org> wrote:
> >> On 27.11.2012 2.35, Eric Wong wrote:
> >>>>
> >>>> nginx does not explicitly unlink the old pid file before it renames it
> >>>> out of the way so yes matching nginx in that regard changes the behavior
> >>>> exactly how I originally asked but you were against that. Maybe the
> >>>> point is moot though.
> >>>
> >>> Ah, I thought you wanted the pid file to be replaced without
> >>> a window where the file is non-existent (or empty).
> >>
> >> That would be ideal but I meant this thread to be explicitly about the
> >> unlink and resulting couple seconds window. Now that I have spend some
> >> thinking about the issue here's an approach using hard links that can be
> >> used to replace the pid without window of non-existance:
> > 
> > Yes, this is ideal, but unfortunately, the window of non-existence is
> > necessary for compatibility with some existing (nginx-based) scripts.
> 
> Can you point out what those scripts are?

(Revisiting old archives ...)

OK, I misremembered the situation...

TL;DR: there's too much historical baggage, as unicorn inherits traits
  from both mongrel and nginx.  A change to fix one pid file monitoring
  solution will likely break something else.  Of course PID files
  are broken _anyways_, so relying on them for monitoring is a
  terrible idea, *especially* when it's something like nginx/unicorn
  where a master process gets replaced.

1) Before unicorn, there was Mongrel: it was important for somebody to
   create the PID file early in the process, before binding the listen
   socket.  I seem to recall this being done to make some other health
   monitor work.

2) nginx prevents PID file clobbering by attempting to bind the listen
   socket before writing the pid file.  This is the best way to prevent
   PID clobbering for a fresh process.

Unfortunately, unicorn needed to inherit trait (1) from Mongrel to
ease migration for Mongrel users.

However, I also decided PID file clobber prevention in nginx was useful,
so unicorn will not overwrite a PID file of a valid process.
Unfortunately, the unicorn implementation of PID file clobber prevention
is racy as it cannot copy nginx behavior here while preserving Mongrel
compatibility.

Thus, unicorn unlinks the PID file before writing a new one.
unicorn could rename the PID file out of the way before writing
a new one (as nginx does) and not suffer bad consequences, but
the file still disappears momentarily.

There could be a minor tweak to allow clobbering of an existing
PID file iff it matches an expected value (of the original process),
but I don't think its worth the effort to implement at this point;
as it will still be racy.

Really, PID files are horrible, and MORE horrible than usual
because we support process upgrade/backout via fork+exec().
_______________________________________________
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

  reply	other threads:[~2012-11-27 21:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-25 23:27 pid file deleted briefly when doing hot restart Petteri Räty
2012-11-26  0:43 ` Eric Wong
2012-11-26 10:39   ` Petteri Räty
2012-11-26 18:24     ` Eric Wong
2012-11-26 23:56       ` Petteri Räty
2012-11-27  0:35         ` Eric Wong
2012-11-27  1:49           ` Petteri Räty
2012-11-27  2:02             ` Eric Wong
2012-11-27 16:11               ` Petteri Räty
2012-11-27 21:51                 ` Eric Wong [this message]
2012-11-27  1:50           ` Petteri Räty

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=20121127215146.GA23452@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).