So I've read that mongoose driver for NodeJS caches queries until it connects to MongoDB (no timeouts). But when the db crashes it should be possible to send a message to the user. So let's look at this NodeJS code:
Users.find({}, function(err, result) {
// Do something with result and send response to the user
});
This may be hanging at infintum. So one way to fix this problem is to do the following
var timeout = setTimeout(function() {
// whem we hit timeout, respond to the user with appropriate message
}, 10000);
Users.find({}, function(err, result) {
clearTimeout(timeout); // forget about error
// Do something with result and send response to the user
});
And the question is: is this a good way? What about memory leaks (hanging queries to MongoDB)?