mongodb / specifications

Specifications related to MongoDB
http://specifications.readthedocs.io/en/latest
Other
389 stars 242 forks source link

Why maxIdleTimeMs defaults to zero? #1476

Closed fredmaggiowski closed 9 months ago

fredmaggiowski commented 11 months ago

While investigating some issues about connection management in one of the services of my application I stumbled upon the maxIdleTimeMs default value which is set to 0 meaning that there is no idle limit and therefore connection may remain unused but still active.

I was wondering why is that so?

Reading this FAQ (specific to Node.js driver) I see there are concerns about the application being in charge of dealing with pool configuration tuning, so I guess the problem is to find an "ideal" time that works for most of the scenarios?

alexbevi commented 9 months ago

Hey @fredmaggiowski, and thanks for the question. There is nothing inherently wrong with an idle socket, and the driver doesn’t know when it might be needed again, so we decided not to close it after some arbitrary period of time (by default at least).

fredmaggiowski commented 9 months ago

Hi @alexbevi thanks for your reply

There is nothing inherently wrong with an idle socket, and the driver doesn’t know when it might be needed again

I agree, however depending on the server provider there may be a limit on available connections and keeping them open could cause issue.

... and the driver doesn’t know when it might be needed again, so we decided not to close it after some arbitrary period of time (by default at least).

I agree that there is no way for the driver to know this and now understand why the decision has been made.

Thanks!