Mongos connection not cleared

Dear team,

We have MongoDB shard server setup with Router + Config + 2 Shard servers [MongoDB version 4.4] and accessing the mongos connections via 4 servers with PHP7.

Recently add 1 extra server(4+1=5) with PHP8 setup [Same Mongo DB version 4.4] due to upgrade and use the common PHP latest libraries.

In new server mongos connection keep on increasing up to 240 and connections not clear after complete the application process.

So when reached the mongos connection above 450 in all 5 server means mongos disconnected with below error:

PHP Error message:

Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on ''] in 

MongoDB Error log message:

{"t":{"$date":"2023-10-31T08:31:32.410+00:00"},"s":"I",  "c":"NETWORK",  "id":23018,   "ctx":"listener","msg":"Error accepting new connection on local endpoint","attr":{"localEndpoint":"","error":"Too many open files"}}

Mongos connection count when disconnect:

GitHub - mongodb/mongo-php-library: The Official MongoDB PHP library - Use this library to write queries.

Also tried with “maxPoolSize”, “socketTimeoutMS” and “connectTimeoutMS” and tuned that values. But not supported.

Could you please help us to solve this issue?

Thanks in Advance.

Hi @Sivanath_JG and welcome to MongoDB community forums!!

I see that its been long that you have not received a response. I hope the issue has been resolved. However for further reference adding more information below.

Ideally, the PHP Drivers reuses the connections opened and these connections are kept open until the process terminates unless the processes have been started with different parameters.
You can find more details to the Is there documentation on MongoDB\Client's connection persistence behavior? on persistent connections handling.

The error that you are observing in MongoDB generally occurs when we hit the system limit. The recommendation would be to visit the documentation on recommended-ulimit-settings for further details.

You might also want to visit the documentation for server selection errors for further details.

Also can you help me with the output for php -i | grep -i mongo where you are running the MongoDB deployment.

Finally, if you are connected on on-prem MongoDB, you might want to try the Atlas Free Tier for latest releases and compatibility with all the supported drivers.

Best Regards