Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with automatic failover with sharded and replicated Mongodb setup
    text
    copied!<p>I'm using Mongodb with only one shard and 3 members in a replica set. I have each replica set member on a different machine. Two members each have a <code>mongos</code> router, one member (that has a router) has a <code>config</code> server, and all three have a shard server. I have one hostname that resolves to the two ip addresses of each one of the mongodb instances that has a <code>mongos</code> router. I'm using mongoose v.2.5.10 to connect to mongodb from my node.js application with the following code:</p> <pre><code>var mongoose = require('mongoose'); mongoose.connection.on('error', function(err){ console.error('Mongodb connection error: ', err); }); var db = mongoose.connect('mongodb://username:password@' + mongoHost + '/database'); </code></pre> <p>I simulate what would happen in a failover scenario by terminating one of the mongodb instances that has the <code>mongos</code> router, and when this happens, I detect that the instance is down and prune the instance's ip address from the DNS record. However, my application does not seem to correctly reconnect to mongodb, as the <code>error</code> event of the mongoose <code>connection</code> is not being emitted, and my application hangs until I restart my node server.</p> <p>What might be going wrong here?</p> <p><strong>UPDATE:</strong></p> <p>I've just confirmed that the <code>net</code> client that the mongodb node.js client is using to connect (<code>this.connection = net.createConnection(this.socketOptions.port, this.socketOptions.host);</code>) is not receiving the <code>close</code> or <code>error</code> event when I manually terminate the Amazon instance. So this seems like this could be an internal node issue...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload