Mongodb – Why mongodb never end some connection

mongodbmongodb2.4

My mongod runs out of connections from time to time. But when I restart the instance, it becomes normal.

I check the log and found some connections were created and never be ended. This cause the connection depleted quickly.

My mongo cluster consists of of 3 shards, each with 3 replicasets. So there are 9 mongod instance and 5 mongos instance. The problem occurs in one of the mongod instance.

I am running mongo version 2.4.

Here is part of the log:

Tue Sep  1 23:24:09.245 [initandlisten] connection accepted from 10.1.1.2:35569 #987213 (291 connections now open)
Tue Sep  1 23:24:09.687 [conn987214] end connection 10.1.1.1:36381 (339 connections now open)

Best Answer

Find out how many connections are there to the database vs how many available. This command in Mongo Shell will tell you exactly that:

db.serverStatus().connections