Bug in c# Driver 2.11.0

After many hours trying to figure out the issue i have found that the C# Drivers 2.11.0 have an issue. Depending on what other third party libraries have been used before using the driver they will just throw timeouts exception. Reverting the Driver to 2.10.4 fix the issue. So it’s something that have been added between both version. Right now i have found that if you open a MongoClient at the begining of the application (first line in the program.cs) it will work even after calling the third party dll’s that cause mongo to fail. If instead you call any of these third party dll then try to make any call to mongo you will always have timeout error. I have more details on the operation i was doing over at stackoverflow https://stackoverflow.com/q/63305491/2748412

Is there anyways to use allowDiskUse on a find with version 2.10.4

Hi @CyberFranck_N_A and welcome to the forums,

The allowDiskUse option is specific for MongoDB Aggregation framework only. The option enables writing to temporary files. When set to true it allows aggregation stages to write data to the _tmp subdirectory in the dbPath directory.

This is not related to a specific MongoDB driver or version, this is the behaviour of the server.

Looking at the error stack trace that you posted on StackOverflow:

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 : “Automatic”, Type : “Unknown”, State : “Disconnected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “127.0.0.1:27017” }”, EndPoint: “127.0.0.1:27017”, ReasonChanged: “ServerInitialDescription”, State: “Disconnected”, ServerVersion: , TopologyVersion: , Type: “Unknown”, LastHeartbeatTimestamp: null, LastUpdateTimestamp: “2020-08-07T16:00:54.4780565Z” }] }.

Also from the server log:

{“t”:{"$date":“2020-08-07T12:31:05.334-04:00”},“s”:“I”, “c”:"-", “id”:20883, “ctx”:“conn249”,“msg”:“Interrupted operation as its client disconnected”,“attr”:{“opId”:4183920}}
{“t”:{"$date":“2020-08-07T12:31:05.334-04:00”},“s”:“I”, “c”:“NETWORK”, “id”:22989, “ctx”:“conn249”,“msg”:“Error sending response to client. Ending connection from remote”,“attr”:{“error”:{“code”:6,“codeName”:“HostUnreachable”,“errmsg”:“Connection reset by peer”},“remote”:“127.0.0.1:61403”,“connectionId”:249}}

From a brief look, it is likely that the client was disconnected from the server. Is there something on the network layer that is interrupting the connection ?

If you’re still encountering this issue, and able to reproduce it consistently, could you please provide:

  • MongoDB server version
  • Operating System and version
  • A minimal reproducible code example
  • Any other relevant information, i.e. setup etc.

Regards,
Wan.

Error is reproducible 100% of the time.

Switching driver from 2.11.0 to 2.10.4 fix the issue.

MongoDB server version 4.4.0
Windows 10 latest version (brand new pc new install)

example code based on the stack overflow old code that does work :

 // get the client
 var client = new MongoClient("ConnectionStringHere");

// get the database
var db = client.GetDatabase("SomeDatabase");

// create the filter for collection names
var filter = new BsonDocument("name", "SomeCollection");
var options = new ListCollectionNamesOptions { Filter = filter };

// check if the filter return at least 1 record
var containAtLEastOneRecord = db.ListCollectionNames(options).Any();

// declare a third party DLL object
var test = ThirdPartyDll.SomeClass();

here the similar example but this does not work

// declare a third party DLL object
var test = ThirdPartyDll.SomeClass();

 // get the client
 var client = new MongoClient("ConnectionStringHere");

// get the database
var db = client.GetDatabase("SomeDatabase");

// create the filter for collection names
var filter = new BsonDocument("name", "SomeCollection");
var options = new ListCollectionNamesOptions { Filter = filter };

// check if the filter return at least 1 record
var containAtLEastOneRecord = db.ListCollectionNames(options).Any();

Noticed the ONLY difference is that i called another third party dll before yours and it doesn’t work with 2.11.0 but if i switch to 2.10.4 both code works. I do use over 250 third party DLL and only a single one cause that issue if i instantiate it before yours. I have contacted their support and as their dll do not crash and they say it’s up to you to fix your issue. I assumed there must be culture info issue between same dll or something like it that is not standard in your code in 2.11.0 that is correct in 2.10.4

Hi @CyberFranck_N_A,

Thanks for the extra information. Would you be able to share the name of this third party DLL ? Essentially an attempt to create a reproducible test case for others.

Also, do you get any warning or error message during build time ?

Regards,
Wan

The third party DLL is called Eyeshot. It’s a proprietary CAD engine. There is no error or warning regarding this at build time in the list. The only one i get is the runtime exception

A timeout occured after 30000ms selecting a server using CompositeServerSelector…

Hi @CyberFranck_N_A,

Thanks for that information. Unfortunately it’s challenging to debug an issue without a reproducible test case.

Could you try setting up MongoDB on a different machine, and connecting to it remotely ? You could try to spin up your own LAN server, or just spin-up free-shared-tier MongoDB Atlas. Just guessing, but I would like to know whether your machine is overloaded on runtime which prevents the local server to responds adequately.

Regards,
Wan.

the DB is not local. I have ordered a brand new PC with windows 10 installed and Mongo community on it and that’s the only thing installed. After test are complete we will create a dedicated VM running on Windows Server. My test are done from my PC connecting to that remote computer. Also i do have the same issue while trying to connect to my local database too. The server is running a Ryzen 9 3950X 16 cores and local i am running the threadripper 3970X 32 cores so being overloaded i don’t think that’s the problem here.

Hi,
I’m spreadly facing the same issue connecting to Atlas on DEV and STAGING environment, i.e. different clients, different Atlas clusters. Cannot say it’s because of a specific 3rd party dll, I’m still investigating.
I’ll try to downgrade the driver to the 2.10.4 on the DEV one and try to reproduce.
For both of my envs I’ve a WebAPI app on Azure Germany which connects to Atlas cluster, both as M0 Sandbox (General) deployed on AWS / Frankfurt (eu-central-1).
PROD is still running with the 2.10.2 with no problems. Also, the code is not changed around the driver usage.

So i might not be just due to the DLL loading order even if i can actually reproduce this every single time by changing the order only ?

Today I downgraded the DEV and the STAGING environments to 2.10.4 and later I was debugging a branched codebase running the driver version 2.11.0 getting the timeout too.
I downgraded the driver in the branched as well to 2.10.4 and I’m not facing the issue anymore.
Unfortunately I have no so much time to investigate into this deeper, but I’m 100% sure the code around the driver wasn’t changed and the only difference is the driver version. I’ll wait the next version to check if the issue is solved.

I have the same problem with just a simple WinForms application trying to enumerate DB’s on the local server.
The problem was intermittent and was solved when I downgraded to driver version 2.10.4.
The only thing I did on the server is define an admin user with password protection on the DB.

Hi @Oren_Lev, and welcome to the forum,

Although you may see a similar error message, the cause may be entirely different. For example, both a third party DLL interference versus network interference could cause a CompositeServerSelector issue (amongst other things).

If the issue that you are encountering is reproducible, please open a new discussion thread/topic. Please provide:

  • Example WinForms application
  • MongoDB server version
  • Architecture of the application/server. i.e. remote, Atlas, etc.

Best regards,
Wan.

1 Like