I am using node.js & MongoDB, and I have asynchronous code (async.queue
) to update MongoDB.
When all the tasks in the queue is finished, I call
db.close() // db is a Mongo client instance
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.
I researched and found that maybe I should set this option maxIdleTimeMS
, but this option is not supported by all drivers (node.js driver does not support this option).
Even if I can fine tune my code to make sure there is no such condition that close()
is not called. I am still wondering what if an app does not call db.close()
for some reason (or as an extra insurance), is there any way to prevent hanging connections in MongoDB?