pid file deleted briefly when doing hot restart

Eric Wong normalperson at
Mon Nov 26 18:24:38 UTC 2012

Petteri Räty <betelgeuse at> wrote:
> On 26.11.2012 2.43, Eric Wong wrote:
> > Petteri Räty <betelgeuse at> wrote:
> >> What follows are all the write actions related to unicorn pid file when
> >> doing a hot restart. Seems like a bug to me that unicorn is deleting the
> >> pid file before writing the new file. Is there a reason for it? It seems
> >> to go against that rename that aims for an atomic replace that would
> >> always ensure the pid file is there.
> > 
> > Unfortunately, pid files are inherently racy.  However, I
> > seem to recall a pid file not existing for a brief moment was needed
> > to allow some nginx-based scripts to work.
> > 
> Would you be open for a config switch to avoid this behavior?

No, every config option makes the project more difficult to support.

> Can you say if lib/unicorn/http_server.rb:196 is the correct spot?


> The use case here is that with health monitors wouldn't have a window
> where a pid file does not exist. With a hot restart it should always be
> possible to have a pid file that points to either the old or the new master.

Then, doesn't nginx have the same problem?

> > I think unicorn differs a bit from nginx here:
> > 
> > nginx uses rename() to clear the way for a new pid file.  Like unicorn,
> > this still leaves a window where no pid file exists.
> > 
> Looking at the inotify log it seems the reason pid file does not exist
> is an explicit delete and not due to rename. It happens a couple seconds
> earlier also so the window is possible to hit even with a periodic poller.

Is matching nginx rename behavior enough to solve the problem?

Matching nginx behavior can become the default if it solves your problem.

More information about the mongrel-unicorn mailing list