Hi,
My server is started by another process that hands it a socket on file descriptor 11. I start my server this way:
http.createServer(app).listen({fd: 11});
Now I want to modify this to enable zero-downtime deployments, so I would like to have naught start my server. The question is: how can I get naught to pass fd 11 to my script so that I can listen on it? Or, how do I "connect" naught's fd 11 with my script's fd 11?
I have tried modifying naught's spawn invocation so that it reads:
var stdio = [process.stdin, stdoutValue, stderrValue, 'ipc'];
stdio[11] = 11;
master = spawn(process.execPath, nodeArgs.concat([path.join(__dirname, "master.js"), workerCount, script]).concat(argv), {
env: process.env,
stdio: stdio,
cwd: process.cwd(),
});
Basically I have added "stdio[11] = 11;" However this doesn't seem to be working. My server is failing to listen, getting the error "Error: listen ENOTSOCK". The node documentation says a positive integer in the stdio array "is interpreted as a file descriptor that is is currently open in the parent process. It is shared with the child process". I'm wondering if the problem is that the file descriptor, though available to my parent process, is not open yet. If so, how should I open it? Just fs.open?
Is there some way for naught (or any process) to know which fds are being made available to it, and pass them on to the child without needing to be told what they are? Is it possible for a process to automatically pass all fds to a child without having to enumerate them?
I have also filed this issue as a naught ticket but haven't heard back yet:
https://github.com/andrewrk/naught/issues/65