christkv/node-mongodb-native — Issue #488: Queries stalling if issued "synchronously"
Author: novemberborn
Created: 2012-01-25 15:59:57+00:00
State: open

A few places of our app run two `findOne` queries immediately after each other. Since upgrading from 2b989fd9f6b4c94f99a7fd529ba897afa5769097 to 385e9ddf3433cda210fb82dc81540817b60bdb23 ([see compare view](https://github.com/christkv/node-mongodb-native/compare/385e9ddf3433cda210fb82dc81540817b60bdb23...2b989fd9f6b4c94f99a7fd529ba897afa5769097)) this has been failing more often than succeeding.

An example method:

```js
function lookup(cb){
var a, b;
var waiting = 2;

collA.findOne({ a: true }, function(err, result){
a = result;
waiting--;
if(waiting === 0){
cb(null, [a, b]);
}
});
collB.findOne({ b: true }, function(err, result){
b = result;
waiting--;
if(waiting === 0){
cb(null, [a, b]);
}
});
}
```

More often than not one of these queries would stall. Reproducible even with master.

We've been able to work around this for now by querying `collA` and then `collB` but obviously that slows things down a bit.

Also of note, we're connected to a replicaset with three servers and a pool size of 4.

@miksago theorizes that the underlying cursors are failing to distinguish the server responses.