All Products
Search
Document Center

ApsaraDB for MongoDB:How do I troubleshoot database connection failures after the number of connections reaches the upper limit?

Last Updated:Apr 28, 2024

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 Overview.

  • 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

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and region to which the instance belongs.
  3. In the left-side navigation pane, click Sharded cluster instance.
  4. On the page that appears, find the instance that you want to manage and click its ID.
  5. In the left-side navigation pane, click Monitoring Data.

  6. On the Monitoring Data page, check the Connections information. The following figure shows that the number of connections to the instance is 500.

    Note

    If the instance is a sharded cluster instance, you must select the Mongos node in use in the upper-right corner on the page.

  7. In the left-side navigation pane, click Basic Information.

  8. On the Basic Information page, query the maximum number of connections corresponding to the current instance specifications. In this example, the number is 500.

    Note

    Based on the number of current connections, you can confirm that 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 or a node. 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.