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.
Prerequisite Checks
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 msMongoServerSelectionError: connection timed outMongoServerSelectionError: getaddrinfo ENOTFOUNDNo suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve '<my-database-host>]
Check Deployment Availability
On Atlas deployments, confirm that the cluster state is
Activein the Atlas UI's Clusters page with the green dot status indicator.On self-managed deployments, verify that the
mongodprocess is running and listening on the expected port.
Check Log Messages
Enable log messages in your server or driver to confirm that the client is repeatedly attempting server discovery until the timeout expires.
Client Logs
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.
Server Logs (Self-Managed)
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.
Common Issues and Resolutions
The following sections describe common causes of server selection timeouts and how to resolve them.
Local Network or Firewall Blocking Connections
If the client cannot establish a TCP connection to any host in the deployment, server selection fails.
To restore connectivity:
Verify that outbound traffic from the client host is allowed on TCP port
27017(or the configured custom port).Check firewall rules, security groups, and network ACLs for restrictions.
Ensure that no VPN, proxy, or local firewall is intercepting the connection.
Retry the connection after making changes.
Client IP Address Not Allowed (Atlas)
If the cluster is available but receives no incoming connections:
In the Atlas UI, navigate to Network Access.
Verify that the client's public IP address is included in the IP access list
If needed for testing, temporarily allow access from
0.0.0.0/0.Save the changes and wait for the configuration to apply.
Retry the connection.
For more information about IP access lists, see Configure IP Access List Entries.
DNS SRV Resolution Failure
If the client reports errors such as ENOTFOUND or fails during SRV (Service) lookup,
the environment may be unable to resolve DNS SRV records.
Verify DNS SRV Resolution
Follow these steps from the client host:
Identify the hostname from the connection string:
mongodb+srv://<cluster-name>.mongodb.net Run a DNS SRV lookup:
nslookup -type=SRV _mongodb._tcp.<cluster-name>.mongodb.net Verify that the command returns one or more SRV records pointing to MongoDB hosts.
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.
Work Around SRV Limitations
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.
TLS Configuration Issues
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).
Verify Resolution
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.
Diagnostics to Collect for More Support
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