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

Deadlock in mongo db C# drivers when using legacy MongoServer and WebApi

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.0
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      Tested under Windows 8.1 x64 / IISExpress / VS 2013 Up 4 / VS 2015 Preview.

      A recent change (inf to 14 days) has introduce a deadlock issue when using the driver in a WepAPI project.

      Tested on version master (commit fd5d79c5351e56847ed5d82eed946db609ccdb88)

      Steps to reproduce (A sample project is attached)

      • Create a Web api project (.NET 4.5.1)
      • Add C# driver from GitHub
      • Use the legacy MongoServer class to get database and collection reference.
        public ValuesController()
                {
                    this.client = new MongoClient(serverUrl);
                    this.server = this.client.GetServer();
                    this.database = this.server.GetDatabase(databaseName);
        
                    this.collection = this.database.GetCollection<MyResource>("Resources");
                }
        
      • In a WebApi controller, add a call to FindAll (for example) in an async method
        public async Task<IEnumerable<Resource>> Get()
                {
                    return await Task.FromResult(this.collection.FindAll());
                }
        
      • Run web site and call twice the same resources. The second call will stay block in
        public static TResult Execute<TResult>(this IReadOperation<TResult> operation, IReadBinding binding, CancellationToken cancellationToken = default(CancellationToken))
                {
                    var awaiter = operation.ExecuteAsync(binding, cancellationToken).GetAwaiter();
                    return awaiter.GetResult();
                }
        

        The new High level API work fine

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            phenixdotnet Vincent Lainé
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: