mongodb/node-mongodb-native — pull request #889 by natesilva (2013-02-21 01:09:59+00:00)
Title: Ensure MongoClient.connect closes connection if an error occurred

Currently `MongoClient.connect` prevents Node from exiting if an authorization failure occurs.

It assumes that if `Db.connect` returned an error, that the database wasn’t open. But in fact, `Db.connect` can return *both* and error and a `db` object.

So, in case of an error, check for a `db` object, and if it exists, close the connection.