title: MongoDB: Server sockets closed after a few minutes
body: <p>I am working with multiple AWS intances connected to the same mongo database (inside Compose.io Elastic deployment) but I keep getting the error <code>server &lt;url&gt;:&lt;port&gt; sockets closed</code> after a few minutes. Can anyone give me any hint about what may be wrong with the connection code?</p>
  
  <p>CONNECTION CODE</p>
  
  <pre><code>var url = "mongodb://&lt;user&gt;:&lt;password&gt;@&lt;url1&gt;:&lt;port1&gt;,&lt;url2&gt;:&lt;port2&gt;/&lt;dbName&gt;?replicaSet=&lt;replicaSetName&gt;"; 
  var options = { 
      server : {"socketOptions.keepAlive": 1}, 
      replSet : { "replicaSet": &lt;replicaSetName&gt;, "socketOptions.keepAlive": 1 } 
  }; 
  MongoClient.connect(url, options, function(err, db) { ... });
  </code></pre>
  
  <p>ERROR MESSAGE</p>
  
  <pre><code>Potentially unhandled rejection [2] MongoError: server &lt;url&gt;:&lt;port&gt; sockets closed 
  at null. (/var/app/current/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:328:47) 
  at g (events.js:199:16) 
  at emit (events.js:110:17) 
  at null. (/var/app/current/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:101:12) 
  at g (events.js:199:16) 
  at emit (events.js:110:17) 
  at Socket. (/var/app/current/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:142:12) 
  at Socket.g (events.js:199:16) 
  at Socket.emit (events.js:107:17) 
  at TCP.close (net.js:485:12)
  </code></pre>