title: In MongoDB, how to make sure all connection will be closed if close() might not get called sometimes?
body: <p>I am using node.js &amp; MongoDB, and I have asynchronous code (<code>async.queue</code>) to update MongoDB.</p>
  
  <p>When all the tasks in the queue is finished, I call</p>
  
  <pre><code>db.close()   // db is a Mongo client instance
  </code></pre>
  
  <p>hence all connections used by the tasks are closed. However, in rare condition, I found there are open connections that are never closed seen in mongoDB logs. So after a few weeks, there will be hundred of connections never closed.</p>
  
  <p>I researched and found that maybe I should set this option <code>maxIdleTimeMS</code>, but this option is not supported by all drivers (node.js driver does not support this option).</p>
  
  <p>Even if I can fine tune my code to make sure there is no such condition that <code>close()</code> is not called. I am still wondering what if an app does not call <code>db.close()</code> for some reason (or as an extra insurance), is there any way to prevent hanging connections in MongoDB? </p>