MongoDB Connection Timeouts (Azure)

I have an application hosted on Windows Azure with the MongoLab add-in, and I have a problem when the application works fine after I deployed it, however, after a period of inactivity for a couple of minutes I get the database error:

There is no replica set available for querying with ReadPreference PRIMARY

This error does not disappear until I restart the website that returns the same template - it works fine until a couple of minutes of waiting when the error returns

My application base code:

mongoConnect(process.env.CUSTOMCONNSTR_MONGOLAB_URI, { server: { auto_reconnect: true, socketOptions: { socketTimeoutMS: 120000, keepAlive: 1 } }, replSet: { socketOptions: { socketTimeoutMS: 120000, keepAlive: 1 } } }).then(function (db) { //app configure ... http.createServer(app).listen(app.get('port'), function () { console.log("Express server listening on port " + app.get('port')); }); }); 

* mongoConnect - a simple "multidisciplinary" function of mongoclient.connect

I understand that this is best practice, I establish one connection to db and then reuse this db object for all requests. From reading the likes of https://support.mongolab.com/entries/23009358-Handling-dropped-connections-on-Windows-Azure I set my expectations on sockets to 2 minutes to prevent firewalls that kill sockets prematurely and auto-connect to true so that they reapply, but none of these problems solves the problem.

+4
source share

All Articles