joyent/node — Issue #2334: `node` can't `fork(2)` safely
Author: mmalecki
Created: 2011-12-14 20:02:20+00:00
State: open

Seems like this has something to do with file descriptors getting screwed during forking.

I'll try describing this problem using problems we've had with [`forever`](https://github.com/nodejitsu/forever).

When `forever` [forks](https://github.com/nodejitsu/forever/blob/master/lib/forever.js#L338-367), it tries to start up a Unix socket server. It worked with `node v0.4` but doesn't work with `node v0.6`. Bad Unix socket persist, causing `ECONNREFUSED`. Also, unlinking `pid` file is not possible.

Module we're using for forking is [`daemon.node`](https://github.com/indexzero/daemon.node).

I think that forever isn't the only usecase for forking processes (right now there's no native way to background a node process without killing it!).

@bnoordhuis told me that `node` (including `libuv`) isn't fork-safe and that making it fork-safe isn't even taken into consideration. Can we reconsider it?