1

Is there a way to synchronously check if a mongod instance (using mongoclient) is still running?

I have a db.on('close') handler in my mongoclient module which works in cases of mongod exiting normally, but if I kill the server process my node app is left hanging completely, unable to return to its normal duties. All requests are blocked and there is no timeout.

The app will resume as normal when mongod is started again so surely there's something that can be done to kill the app if it's waiting too long.

I can only think of doing this synchronously as making another callback to db.runCommand({serverStauts: 1}) will surely get caught in the same state.

1 Answer 1

1

I attached a similar handle for db.on('close') to the 'error' event and it works like a charm.

Heres the code I used (inside of mongoclient.open)

db.on('error', function() {
                close(); // calls mongoclient.close()
                return callback('Lost MongoDB!', null);
            });

Not the answer you're looking for? Browse other questions tagged or ask your own question.