Search code examples
c#azure-cosmosdbazure-cosmosdb-mongoapi

MongoDB timeout Exception (C#)


We're developing a chatbot using microsoft framework (v3) along with cosmos's mongo API. We've had no issues up until recently when the bot suddenly stopped working locally. On further inspection, we found that we were getting a timeout exception.

"A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/hakeemdb.documents.azure.com:10255" }", EndPoint: "Unspecified/hakeemdb.documents.azure.com:10255", State: "Disconnected", Type: "Unknown" }] }. "

Interestingly enough the bot still works when it is deployed to skype, the problem only seems to occur locally. When querying to database directly, queries run without a hitch, it only seems to be a problem when running the bot locally. We've had updated all our mongo drivers to the most up to date stable versions with no luck.

We've also tried solutions from the following links:

MongoDB C# 2.0 TimeoutException

https://jira.mongodb.org/browse/CSHARP-1302

https://jira.mongodb.org/browse/CSHARP-2540

I also found this stack overflow post:

MongoDB C# driver timeout

but I'm a little unsure if what it means, although it seems to be very close to the issue we are having.

I haven't included any code because I don't think it's a code issue as it started without any change to any of the code.

Another point that could be important is that recently all our resources in azure were moved to a new region so something could have changed during that. We thought that maybe some securities settings had been changed during the migration and the IP of our workplace was being blocked but the database seems to be set to allow connections from all sources so I'm not sure if that's the issue

Any advice or ideas would be greatly appreciated


Solution

  • In the end the wifi network at my work updated their firewall settings and one of the ports we were using for Mongo was blocked. We bypassed the port restrictions by connecting to the physical local network and it worked after that