Hi, @Johann_Sigurdsson and @Hermann_Baumgartl,
I understand that you’re having connectivity problems when using mongodb+srv:// connection strings. The .NET/C# Driver resolves the associated SRV and TXT records and then resolves the hostnames returned from the SRV response. (The TXT record contains additional options such as replicaSet, authSource, and loadBalanced.) Under the hood, the driver relies on DnsClient.NET to resolve SRV and TXT records and relies on the OS’s DNS resolver for FQDN resolution.
Examining the TimeoutException, I can see that Servers : [], which means that the topology is empty. This can occur if the replica set name in the TXT record does not match the replica set name returned during heartbeats. You can view the replica set name in the TXT record via:
dig -t TXT CLUSTERNAME.PROJECTID.mongodb.net
For example, if your connection string is mongodb+srv://user:pwd@my-cluster-name.9zzzz.mongodb.net/?retryWrites=true&w=majority, then you can run the following command to find the associated TXT record:
dig -t TXT my-cluster-name.9zzzz.mongodb.net
When you connect to your cluster using mongosh, you can run db.hello() to manually heartbeat with a cluster node. This will return the replica set name as setName.
The replica set name in the TXT record must match the replica set name returned by cluster members. If your connection string says that you’re connecting to replicaSet=atlas-abc123-shard-0 but the nodes say that they’re part of setName:atlas-xyz987-shard-0, then those nodes will be removed from the topology since they belong to the wrong replica set.
Replica set names are configured automatically in Atlas and are not modifiable by users. They are also not updated after cluster creation. Thus it is unexpected that the replica set name in the TXT record and returned by the cluster members would differ.
There are other edge case scenarios where a misconfigured cluster can result in an empty topology, but these misconfigurations aren’t possible in Atlas. These scenarios would require reusing hostnames for new clusters, which Atlas does not do.
I have attempted to reproduce the reported behaviour but have so far been unsuccessful in observing the problem. If you have a self-contained repro that reproducibly elicits the behaviour, I would be happy to investigate further. Thanks in advance for any additional information that you can provide.
Sincerely,
James