indexzero/daemon.node

In server daemon, fs.asyncFun only works after killing 1st request

jiem opened this issue · 4 comments

jiem commented
var daemon = require('daemon');
var fs = require('fs');
var http = require('http');

http.createServer(function(req, res) {
  fs.readFile('yourFile', 'utf8', function(err, data) {
    res.end(data);
  });    
}).listen(8080);

daemon.daemonize('app.log', 'app.pid', console.log);

The above server freezes at the 1st http request, fs.readFile never triggers the callback.
It's only after killing the 1st request in the browser that everything works.

I am seeing similar problem with making HTTP requests:

var DAEMON = require('daemon');
var HTTP = require('http');

function makeRequest(number)
{
    var request;

    request = HTTP.request({
        method: "GET",
        host: "github.com",
        port: 80,
        path: "/pinf/server-js/zipball/v0.1.21"
    }, function(response) {
        console.log("got response: " + number);
    });

    request.on("error", function(error)
    {
        console.log("got error: " + number);            
    });

    console.log("make request: " + number);
    request.end();
}

makeRequest(1);
makeRequest(2);

DAEMON.daemonize('app.log', 'app.pid', console.log);

makeRequest(3);

The output of app.log is only:

null 1415

If I move all makeRequest() calls to before DAEMON.daemonize() same problem. If I move them all to after DAEMON.daemonize I get:

null 1329
got response: 2
got response: 1
got response: 3

Furthermore if I do:

DAEMON.daemonize('app.log', 'app.pid', console.log);
makeRequest(1);

The script hangs until the request times out and there is only the pid in app.log.

So the first callback never completes if there is only one callback.

@indexzero This is causing me a lot of grief. I hope the fix is easy.

node -v
v0.6.4

@cadorn I have no plans of supporting this library on 0.6.x ... there is a better way to do daemonizing with .fork(). See mmalecki/forever@31fcd47

Ok. Thanks!