pid file deleted briefly when doing hot restart

Petteri Räty betelgeuse at
Mon Nov 26 10:39:56 UTC 2012

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?

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.

> 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.


More information about the mongrel-unicorn mailing list