3

I have an application running on node and using the mongodb library to establish connection and closing it. But the problem is, from the mongo serverStatus() command i can see that there is still 2k+ current connections still available.

> db.serverStatus().connections
{ "current" : 2993, "available" : 835867, "totalCreated" : 220841 }

and most of it are having the active: false status.

My questions is, is there a way for me to force close these idle connections which after some time will affect my application with an timeout error.

I tried using the killOp() command but these only works if there is still opid value listed in these idle connections.

Appreciate some feedback on how can handle this kind of situations.

2 Answers 2

3

This can be avoided by setting up the maxIdleTimeMS parameter of Connection Pool Options

This maxIdleTimeMS parameter sets the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed.

Set this parameter as per your requirement. So the idle connections will be closed once the time limit exceeds.

2
  • Thank you for the response. Our Dev team are looking into the application driver that are initiating these mongo connection. Apr 22, 2019 at 7:15
  • @NazmilBINNORDDIN Are you able to resolve the issue?
    – Mani
    Apr 23, 2019 at 17:18
0

The other answer correctly addresses how to kill future connections, but not present ones.

To address currently opened connections, use db.killOp().

You need to pass a filter to target only the idle connections. In this case, you're looking for {active: false}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.