I've been searching a lot for unexpectedly closed connections in mongodb but can only find questions from people who WANT their connections to close.
I am using node-mongodb-native to connect to a db, but I keep getting seemingly random "Error: connection closed" messages. If I manually retry the request (browser refresh) the request works.
Any idea what is causing this? Is there some simple option that will help?
I'm getting my db handle using:
MongoClient.connect(connection_string, { auto_reconnect: true }, function (err, db) {
//server code/routes in here
}
I was looking through https://github.com/mongodb/node-mongodb-native/blob/master/lib/mongodb/connection/server.js but I realize my limited understanding of how connection pools are managed in general is tripping me up. I was under the impression they would stay open for the lifetime of my server. Can someone help?
Edit: After reading mjhm's comments, I started looking more deeply into TCP keep alive. Stumbled across some sites that suggest this may be Azure's doing (and this question is now misclassified!). Apparently, the Azure load balancer kills connections after 1 min of activity. I'm using Azure Websites, so it may or may not apply, but I think this insight is promising enough to start a new line of investigation. More details here http://blogs.msdn.com/b/avkashchauhan/archive/2011/11/12/windows-azure-load-balancer-timeout-details.aspx