Node.js service chokes and dies once a day
Everyday this week I've been beginning my workday with restarting our node service. And everytime it has simply exited with the following message:
node.js:134
throw e; //开发者_C百科 process.nextTick error, or 'error' event on first tick
^
Error: ETIMEDOUT, Connection timed out
at Socket._readImpl (net.js:163:14)
at Socket._onReadable (net.js:633:22)
at IOWatcher.onReadable [as callback] (net.js:177:10)
I'm having trouble discerning exactly wich part of my code is responsible for that error, and exactly why that error is so severe that it makes node exit.
Anyways I've done some searching around and figured that this might just be an uncaught error event. I've added a few on('error') listeners to every server instance with a bit of customized log message to make sure it's caught, but to no avail, I still got to work today with the regular error message.. (And is there really such a thing as as 'error' events that must be caught?)
A simple connection timeout shouldn't really crash the whole service.
The service's main purpose is to keep an open tcp connection to a number of connecting clients and to be able to push out commands (It's much like a private botnet for an embedded product). So in effect 95% of the time we're just idling our tcp sockets and sending out keep-alive packets. So it's a requirement that clients can loose connection at any moment without interrupting the service for other connected clients.
We're using latest stable branch node v0.4.13-pre and running on an ubuntu server.
Do you have a callback function associated with the "Error" event for that object?
http://nodejs.org/docs/v0.4.12/api/net.html#event_error_
For all your objects, make sure you have a proper callback for their respective "error" events so they can exit gracefully instead of crashing your program.
Add something like this to your code:
process.on('uncaughtException', function (err) {
console.log('Caught Uncaught exception: ' + err);
});
精彩评论