Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw Exception when kill worker process #12

Open
murvinlai opened this issue Jun 25, 2011 · 0 comments
Open

Throw Exception when kill worker process #12

murvinlai opened this issue Jun 25, 2011 · 0 comments

Comments

@murvinlai
Copy link

In my code, I spawn 5 workers. The app server has an internal counter. If it exceeds 20, then it will app.close(), then process.exit() after 1 second, to make sure all existing request of the app are probably handle before the process ends. so that fugue can respawn the worker again.

here is my code:

app.get('/test', function(sReq, sRes) {
try {
var myCounter = counter ++;
console.log('test is called ' + myCounter);

        if (myCounter >= 20) {
            if (isServerClose) {
                console.log("--- server is closed --- " + myCounter);
                try {
                    sRes.send('ERROR 1 ');
                } catch (ex) {
                    console.log(ex);
                }
            } else {
                isServerClose = true;
                var pids = fugue.workerPids();
                console.log("--- server is going to stop --- " + myCounter + " Worker Id: " + fugue.workerId() + " ProcessId: " + process.pid );
                try {
                    sRes.send('ERROR 2 ');
                } catch (ex) {
                    console.log(ex);
                }
                app.close();
                if (! fugue.isMaster()) {    
                    setTimeout(function() {process.exit();}, 1000);
                }
            }
        } else {
            if (isServerClose) {
                console.log("--- server is closed --- " + myCounter);
                try {
                    sRes.send('ERROR 3 ');
                } catch (ex) {
                    console.log(ex);
                }
            } else {
                sRes.send('TEST');
            }   
        }
    } catch (ex2) {
        console.log("bigger problem now... " + JSON.stringify(ex2));
    }
});

When I do the test, let say , make 500 requests. Then it will crash.

net.js:841
throw new Error('The connection is not writable');
^
Error: The connection is not writable
at Socket._shutdown (net.js:841:11)
at Socket.flush (net.js:521:12)
at Socket.end (net.js:873:14)
at Carrier. (/usr/local/lib/node/.npm/fugue/0.1.2/package/lib/fugue.js:297:18)
at Carrier.emit (events.js:64:17)
at /usr/local/lib/node/.npm/carrier/0.1.1/package/lib/carrier.js:40:16
at Array.forEach (native)
at Socket. (/usr/local/lib/node/.npm/carrier/0.1.1/package/lib/carrier.js:26:13)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:678:14)

I think conn.end() call when the process doesn't exist anymore.

I don't know if it is a bug, or I kill the process in a wrong way. Please advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant