A timeout occured after 30000ms selecting a server using CompositeServerSelector

2,602 views
Skip to first unread message

B Smith

unread,
Nov 30, 2016, 6:51:39 PM11/30/16
to mongodb-csharp
Hi -

I'm completely stumped.  I am using the latest c# drivers (2.3.0.157) and the latest MongoDB (3.2).  The DB is running as a standalone setup with no replication or sharding.  I've tried running locally on Windows as well as remotely on Amazon LINUX.  

I continue to get a timeout error but mysteriously sometimes it just works (maybe once every 20 - 30 attempts).

I am creating the 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'll time out on the logs.Find part of the method.  Here's the full message:

Additional information: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = [] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Direct", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "XX.XX.XX.XX:27017" }", EndPoint: "XX.XX.XX.XX:27017", State: "Disconnected", Type: "Unknown" }] }.


I've tried using the fully qualified host name, adding connect=direct and connect=replicaSet to the connection string, using MongoClientSettings instead of the connection string and everything else I could possibly find on forums and StackOverflow.  I'm at a loss and not even sure where to look next.  Any advice?

Krzysztof

unread,
Dec 3, 2016, 9:13:48 AM12/3/16
to mongodb-csharp
Hi,

We have similar problem, I've written this before but no one helped.
I think there is a problem with libraries mongodb, but very difficult to find a reason.

Regards
Krzysztof

Hassan Faghihi

unread,
Feb 8, 2020, 6:58:02 AM2/8/20
to mongodb-csharp
same issue

Raluca Mechno

unread,
Mar 26, 2020, 3:52:27 AM3/26/20
to mongodb-csharp
Hi,

I have the same issue.
Any solution?

Thanks.
Reply all
Reply to author
Forward
0 new messages