Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-406

Deadlock and TimeoutException when acquiring connection.

      The following code sample causes a deadlock and then a TimeoutException with message "Timeout waiting for a MongoConnection.":

      sample.cs
      using System.Threading.Tasks;
      using MongoDB.Bson;
      using MongoDB.Driver;
      
      namespace TestApp1
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var srv = MongoServer.Create("mongodb://localhost/?maxpoolsize=1&waitqueuetimeoutms=5000");
                  var coll = srv["log"]["log"];
                  Parallel.For(0, 2, i => coll.Insert(new BsonDocument("fld1", "val1")));
              }
          }
      }
      

      The core of problem is: "maxpoolsize" parameter (small value), number of iterations (more than "maxpoolsize") and the parallel execution.
      I can reproduce this bug only with small values of "maxpoolsize", but I marked this bug as "Major" because I looked at the driver code and I think this deadlock can occur for any value of "maxpoolsize".

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            proman Pantyushin Roman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: