christkv/node-mongodb-native — Issue #421: MongoHQ issue
Author: christkv
Created: 2011-11-29 21:49:12+00:00
State: open

Hi Christian,

I am taking the liberty to contact you since I am encountering random application crashes related to mongodb. I have been battling with this for a couple of weeks now. The MongoHQ guys looked at it without success and I hope you don't mind taking a quick look to help me out.

Basically, I am running a node.js application on Heroku (express, node-mongodb-native connecting to MongoHQ). Here is my code. I have included part of my code here. I can send you the whole thing if you want. Basically, it seems that if I call _find once at a time, it seems to hold while if I do 2 or more concurrent requests, I get the following exception.

I am pretty desperate at this point and any help would be greatly appreciated.
Thanks a lot,
-Eric

params.criteria --> {"conversations.user_id":"4e9fc8d55883d90100000003","conversations.lc_status":{"$in":["assigned","accepted","done","closed"]},"doer_rating":{"$exists":false}}
params.getOptions() --> {"skip":0,"limit":15,"sort":{"updated":-1}}
{ stack: [Getter/Setter],
arguments: undefined,
type: undefined,
name: 'MongoError',
'$err': 'BSONElement: bad type 50',
code: 10320 }
params.criteria":{"user_id":{"$ne":"4e9fc8d55883d90100000003"},"lc_status":"available"}
params.getOptions() --> {"skip":0,"limit":15,"sort":{"updated":-1}}
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connection closed to [staff.mongohq.com:10023]
at [object Object]. (/app/node_modules/mongodb/lib/mongodb/connection/server.js:184:51)
at [object Object].emit (events.js:67:17)
at [object Object]. (/app/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:110:14)
at [object Object].emit (events.js:67:17)
at Socket. (/app/node_modules/mongodb/lib/mongodb/connection/connection.js:313:12)
at Socket.emit (events.js:64:17)
at Array. (net.js:829:12)
at EventEmitter._tickCallback (node.js:126:26)
Error H13 (Connection closed without response) -> POST hollow-waterfall-4674.herokuapp.com/task/prospects dyno=web.1 queue= wait= service= status=503 bytes=
Error H13 (Connection closed without response) -> POST hollow-waterfall-4674.herokuapp.com/task/available dyno=web.1 queue= wait= service= status=503 bytes=
Process exited
State changed from up to crashed

-----------------------------
provider.js
-----------------------------

var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;

Provider = function(name, host, port, user, pass, num) {
var self = this;
this.db = new Db(name, new Server(host, port, {auto_reconnect : true, poolSize : num}), {native_parser:false});
this.db.open(function(err, driver_db) {
if(err) throw(err);
self.authdb = driver_db;
driver_db.authenticate(user, pass, function(err, result) {
console.log("authentication: "+result);
});
});
};

Provider.prototype.getTaskCollection = function(callback) {
this.authdb.collection('tasks', function(err, coll) {
console.log('coll: '+coll);
if(err) callback(error);
else callback(null, coll);
});
};

exports.Provider = Provider;

-----------------------------
core.js
-----------------------------
function _findTask(params, callback) {
provider.getTaskCollection(function(err, coll) {
if(err) {
callback(err);
return;
}
coll.find(params.criteria, params.getOptions(), function (err, cursor) {
if (err) {
callback(err, null);
return;
};

cursor.count(function(err, count) {
if (err) {
callback(err, null);
return;
};
if (count == 0) {
callback(err, [], count);
} else {
cursor.toArray(function (err, docs) {
if (err) {
callback(err, null);
return;
};
callback(err, cdocs, count);
});
}
});
});
});
};