Cleanup on console closed & log error.stack#3
Conversation
Added log of error.stack and cleanup when the Windows console close.
|
This really feels like the wrong way to do cleanup. None of the exit events work asynchroniously, so it's always messy, and data is left. |
|
@FREEZX , maybe I miss-understand how Node works and exit. But I have understood that process.on('SIGINT') handler can perform asynchronous calls. So I tested: // client => Redis client
process.on('SIGINT', function() {
console.log('Process shutdown by SIGINT');
var now = new Date().toString();
console.log('Try to write test-shutdown key with '+now);
client.set('test-shutdown', now, function(err, set) {
console.log('Is written: '+set+', now exit');
process.exit();
});
});And I get (Windows console): The key is correctly created in Redis store. I've also another question. What do you mean by "normal exit": I didn't manage to do the exit cleanup correctly, so after normal exit, rooms are still... in socketio#15 ? |
|
SIGINT is only called when you do ctrl+c. |
|
@FREEZX OK I get it. I agree with you, no way to handle this type of exit (direct process.exit() call) or (obviously) power unpluged or machine destruction. Later we can maybe add an automatic cleanup logic on restart/other nodes detection but I think it add a complex and heavy logic over the module. |
|
@dbrugne That's the only logical solution i can think of. I wonder how 0.9.x handled this. |
Added log of error.stack and cleanup when the Windows console close. 'Exit' seems not to be the right event to take async actions (from http://nodejs.org/api/process.html#process_event_exit), so I removed it.