MongoDB: Timeout occurred after 30,000 ms selecting server using CompositeServerSelector

I am completely at a dead end. I use the latest C # drivers (2.3.0.157) and the latest MongoDB (3.2). The database works as a standalone configuration without replication or shards. I tried to work locally on Windows, and also remotely on Amazon LINUX.

I keep getting a timeout error, but mysteriously sometimes it just works (maybe once every 20-30 attempts).

I create a connection as such:

private static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ToString(); private static readonly string DataBase = ConfigurationManager.ConnectionStrings["MongoDBDatabase"].ToString(); private static IMongoDatabase _database; public static IMongoDatabase GetDatabase(string database) { if (_database == null) { var client = new MongoClient(ConnectionString); _database = client.GetDatabase(database); } return _database; } 

And calling it like this:

 public static List<Earnings> GetEarnings() { var db = GetDatabase(DataBase); if (db == null) return new List<Earnings>(); var logs = db.GetCollection<Earnings>("EarningsData"); var all = logs.Find(new BsonDocument()).ToEnumerable().OrderBy(x => x.Symbol).ToList(); return all; } 

And it will be time on the logs.Find part of the method. Here's the full message:

Additional Information:

After 30000 ms after selecting a server using CompositeServerSelector {Selectors = ReadPreferenceServerSelector {ReadPreference = {Mode = Primary, TagSets = []}}, LatencyLimitingServerSelector {AllowedLatencyRange = 00: 00: 00.0150000}, a timeout is issued. The client view of the cluster state is {ClusterId: "1", ConnectionMode: "Direct", Type: "Unknown", Status: "Disabled", Servers: [{ServerId: "{ClusterId: 1, EndPoint:" XX.XX. XX.XX: 27017 "}", EndPoint: "XX.XX.XX.XX: 27017", Status: "Disabled", Type: "Unknown"}]}.

I tried to use the fully qualified host name by adding connect = direct and connect = replicaSet to the connection string using MongoClientSettings instead of the connection string and everything else that I could find on forums and StackOverflow. I am at a loss and do not even know where to look further. Any tips?

I also have to add, I can connect perfectly from the command line and RoboMongo ...

+1
mongodb mongodb-.net-driver
source share
1 answer

We finally figured out how to get around this problem, but I still don’t understand what is happening. In our case, we have a server on which ~ 10 signal hubs appear that receive their data from MongoDB. It seems that when the application started, he made some quick calls to MongoDB to get the original data set, and although it worked from time to time, in most cases this is not the case. We decided to do this by adding one second delay between loading each SignalR hub, so that the original request was delayed a bit and we had no disagreement.

It is strange that none of these collections has a large amount of data, and the initial load is usually equal to <100 documents per collection (max.). Once things get initialized, it doesn't seem to matter how often we get into MongoDB. It seems to be on initial load.

+1
source share

All Articles