Sunday, 25 January 2015

The way keystonejs handling mongo connection error is wrong!!

The way keystonejs handling mongo connection error is wrong!!

below is how keystonejs deals with connection error:


this.mongoose.connection.on('error', function(err) {

if (keystone.get('logger')) {
console.log('------------------------------------------------');
console.log('Mongo Error:\n');
console.log(err);
}

if (mongoConnectionOpen) {
if (err.name === 'ValidationError') return;
throw err;
} else {
throw new Error('KeystoneJS (' + keystone.get('name') + ') failed to start');
}

})



This "error" is a event of mongoose connection.

keystonejs handles this error event and throws a Error (exception).

This is wrong because that will throw to Nodejs, and this error will be an "uncaughtException".

Nodejs will reboot after it got this error.


That's make sense. However if you push your application to cloud platform, some platforms may strict for mongo connections, they may close/kill your connections, and then you can catch the close event and reconnect. However Keystonejs's solution will throw the error and reboot your application. no matter what you do, even you catch this error yourself, but keystonejs will reboot your application with this wrong reason.

So, my suggestion is Keystonejs should offer user's a setting to set if they want to handle the error themselves? if so, keystonejs should stop throwing this error here.
































































































































































No comments:

Post a comment