socketTimeoutMS not working in very simple environment

I am developing an application. The MongoDB server is hosted on a remote host. So, I am really keen on using socketTimeoutMS: 30000 to make sure that an error is thrown -- and I get to log the problem in my application.

I tried with the URL, setting MONGO_URL as mongodb://localhost/ddd18?socketTimeoutMS=4000'.

Or using the options:

require('mongodb').MongoClient.connect( process.env.MONGO_URL, { server: { socketOptions: { socketTimeoutMS: 6500, connectTimeoutMS: 6500 } } } , function( err, db ){

Or:

require('mongodb').MongoClient.connect( process.env.MONGO_URL, { mongos: { socketOptions: { socketTimeoutMS: 6500, connectTimeoutMS: 6500 } } } , function( err, db ){

Or other combinations in the options (like straight { socketOptions: { socketTimeoutMS: 6500, connectTimeoutMS: 6500 } } or even { socketTimeoutMS: 6500, connectTimeoutMS: 6500 }).

If I do the following:

  • Run my application (which connects fine to MongoDB)
  • Kill MongoDB altogether
  • Try and perform an operation

The attempt will hang forever. Actually, it will hang there, and then when I finally restart MongoDB, the operation will actually start and complete.

The problem I have is that my client has a 30 second timeout. If the server doesn't, and for some reason it goes silent for a couple of minutes, all those operations that the client reported as "failed" WILL actually happen -- and that would be silly.

Am I doing something obviously wrong?

Relevant documentation: http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html

Answer was simple: socket WASN'T timeing out. auto_reconnect was set to true, and the server kept on trying to re-connect -- and not giving out an error