mongodb/node-mongodb-native — pull request #909 by medikoo (2013-03-13 18:40:20+00:00)
Title: Fix async callback handling issue

Inner Logic of `_executeQueryCommand` result looks as:

```javascript
var getMore = function(self, options, callback) {
// ...
self.db._executeQueryCommand(a, b, function(err, result) {
// ...
try {
// ...
callback(null, value);
// ...
} catch (e) {
// ...
callback(err);
// ...
}
});
// ...
};
````

It means that eventual error thrown within callback is propagated back to same callback. That's unexpected, additionally in that case async function callback is called twice, which should never happen.

This patch fixes that to:

```javascript
self.db._executeQueryCommand(a, b, function(err, result) {
var cbValue;
// ...
try {
// ...
cbValue = value;
// ...
} catch (e) {
// ...
callback(err);
// ...
}
if (cbValue != null) callback(null, cbValue);
});
```

Callback is not called with it's own error, and error is freely thrown as it should in such case.