Search code examples
mongodbmongodb-.net-driver

TimeoutExceptions from mongo c# driver with Async API


We are using the latest beta driver from MongoDB (2.0.0-beta2) with all the async capabilities. But compared to the old implementation (1.10.0-rc0) we are getting some weird TimeoutExceptions. We have tried different server versions (among others, also 3.0.0-rc10), but that doesnot seem to influence this.

System.TimeoutException occurred
  HResult=-2146233083
  Message=Operation timed out after 00:00:30.
  Source=MongoDB.Driver
  StackTrace:
       at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__0`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperation>d__5e`1.MoveNext()

We have a hard time reproducing this, firing a couple of thousands inserts, updates and finds does not trigger this bug. However, running our .NET web application does trigger this (after creating a couple of new entities).

The Exception location differs but one of the places is in our FindAll method. Our code does:

IMongoCollection<BsonDocument> col = _database.GetCollection<BsonDocument>(GetCollectionName(qmoType));
IFindFluent<BsonDocument, BsonDocument> findFluent = col.Find(MongoDBWhereBuilder.BuildWhere(where));

findFluent = findFluent.Sort(SortBy.Ascending(sort.Keys.ToArray());
findFluent = findFluent.Skip(skip);
findFluent = findFluent.Limit(take);

List<BsonDocument> list = await findFluent.ToListAsync();

The _database variable is shared between all requests (it is created once at startup).

How can we get a better grip on this problem? Or are there others that have this issue?


Solution

  • This is a bug in the beta2 driver. The fix is merged into master (and part of beta3): https://jira.mongodb.org/browse/CSHARP-1184