After the number of connections to an ApsaraDB for MongoDB instance reaches the limit, new connection requests cannot be responded. This topic describes how to handle database connection failures after the number of connections reaches the upper limit.
Symptom
The maximum number of connections varies depending on ApsaraDB for MongoDB instance types. For more information, see Instance types.
- The application fails to connect to the database.
- The whitelist has been properly set. However, the following error message is displayed
when you use the mongo shell to connect to the database:
2019-07-10T10:30:43.597+0800 E QUERY [js] Error: network error while attempting to run command 'isMaster' on host 'dds-bpxxxxxxxx.mongodb.rds.aliyuncs.com:3717' : connect@src/mongo/shell/mongo.js:328:13 @(connect):1:6 exception: connect failed
- The whitelist has been properly set. However, the following error message is displayed
when you use DMS to connect to the database.
Check whether the number of connections has reached the upper limit
Solution
You can restart the instance to temporarily release all connections. For more information,
see Restart an ApsaraDB for MongoDB instance. To prevent this problem from occurring again, we recommend that you perform the
following operations after restarting the instance:
Note If you restart the instance, all instance nodes are restarted one by one. Each node
has a transient disconnection of about 30 seconds. If there are a large number of
collections (more than 10,000), the transient disconnections last longer. Before restarting
the instance, arrange your business and ensure that your application has a reconnection
mechanism.
- Configure the connection pool. For more information, see Limit the number of connections.
- Analyze the connection sources. For more information, see Query the source IP addresses of the current connections. If the service uses all the connections, upgrade the instance specifications. For more information, see Configuration change overview.