Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /

Troubleshoot Server Selection Timeout

Applications might encounter server selection timeout errors when attempting to connect to a MongoDB deployment. This error indicates that the client driver cannot select a suitable server within the configured timeout period.

Server selection timeouts commonly occur due to network connectivity issues, IP access restrictions, DNS SRV resolution failures, or TLS configuration issues.

This page describes common causes of server selection timeouts and provides steps to diagnose and resolve them. If the issue persists after completing the steps below, contact Technical Support.

To verify that your application is encountering a server selection timeout, review the client error message. Common examples include:

  • MongoTimeoutError: Server selection timed out after 30000 ms

  • MongoServerSelectionError: connection timed out

  • MongoServerSelectionError: getaddrinfo ENOTFOUND

  • No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve '<my-database-host>]

  • On Atlas deployments, confirm that the cluster state is Active in the Atlas UI's Clusters page with the green dot status indicator.

  • On self-managed deployments, verify that the mongod process is running and listening on the expected port.

Enable log messages in your server or driver to confirm that the client is repeatedly attempting server discovery until the timeout expires.

Client logs may show repeated attempts to discover cluster topology, followed by a timeout. Messages may reference:

  • DNS resolution failures.

  • TLS handshake errors.

  • Connection attempts that do not complete.

If the server logs show no incoming connection attempts when you run the getLog command or on your configured log destination, this typically indicates a network connectivity issue.

The following sections describe common causes of server selection timeouts and how to resolve them.

If the client cannot establish a TCP connection to any host in the deployment, server selection fails.

To restore connectivity:

  1. Verify that outbound traffic from the client host is allowed on TCP port 27017 (or the configured custom port).

  2. Check firewall rules, security groups, and network ACLs for restrictions.

  3. Ensure that no VPN, proxy, or local firewall is intercepting the connection.

  4. Retry the connection after making changes.

If the cluster is available but receives no incoming connections:

  1. In the Atlas UI, navigate to Network Access.

  2. Verify that the client's public IP address is included in the IP access list

  3. If needed for testing, temporarily allow access from 0.0.0.0/0.

  4. Save the changes and wait for the configuration to apply.

  5. Retry the connection.

For more information about IP access lists, see Configure IP Access List Entries.

If the client reports errors such as ENOTFOUND or fails during SRV (Service) lookup, the environment may be unable to resolve DNS SRV records.

Follow these steps from the client host:

  1. Identify the hostname from the connection string:

    mongodb+srv://<cluster-name>.mongodb.net
  2. Run a DNS SRV lookup:

    nslookup -type=SRV _mongodb._tcp.<cluster-name>.mongodb.net
  3. Verify that the command returns one or more SRV records pointing to MongoDB hosts.

  4. If no records are returned:

    • Confirm that the hostname is correct.

    • Check whether your DNS provider supports SRV records.

    • Verify that outbound DNS queries are not blocked.

If SRV records cannot be resolved, you need to retrieve the standard connection string (non-SRV) from the deployment update the application to use:

mongodb://host1,host2,host3/?replicaSet=<name>

Retry the connection.

To learn more about connection strings, visit Connection Strings.

If the error output references TLS or SSL handshake failures, you can take the following steps to resolve common TLS configuration issues:

  • Verify that the client driver supports TLS 1.2 or later.

  • Ensure that system root certificates are up to date.

  • For self-managed deployments:

    • Confirm that the certificate hostname matches the connection string.

    • Verify that the full certificate chain is available.

After you complete these steps, retry the connection.

To learn more about TLS/SSL and learn how to configure your TLS/SSL connections, see TLS/SSL (Transport Encryption).

After resolving the underlying issue:

  • The client establishes a connection without timing out.

  • Application logs indicate successful server selection.

  • Atlas metrics (if applicable) show active connections.

  • Server logs record incoming client connections.

If the issue persists, collect the following before contacting Technical Support.:

  • Complete client error messages and stack traces

  • MongoDB connection string (credentials removed)

  • Driver name and version

  • MongoDB server version

  • DNS SRV lookup output

  • Network connectivity test results

  • Relevant MongoDB logs

Back

Connection Storms

On this page