I have an Atlas cluster and I am connecting from my dotnet application using MongoDB C# Driver 2.11.2
The connection string is default mongodb+srv://<user>:<pass>@cluster0.<cluster>.mongodb.net
When launching the app locally everything works fine.
When I deploy it to AKS in 90% cases it failes to connect with a time-out error:
System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [] }.
If I restart a Pod multiple times it will work eventually. So it looks like some transient error.
When I switch to mongodb://
scheme everything works fine in AKS. What is the possible reason of such behaviour in the cloud?