[CSHARP-1133] Deadlock in mongo db C# drivers when using legacy MongoServer and WebApi Created: 28/Nov/14  Updated: 02/Apr/16  Resolved: 04/Dec/14

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0

Type: Bug Priority: Major - P3
Reporter: Vincent Lainé Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: rc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tested under Windows 8.1 x64 / IISExpress / VS 2013 Up 4 / VS 2015 Preview.


Attachments: Zip Archive TestMongoWeb.zip    

 Description   

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



 Comments   
Comment by Githook User [ 04/Dec/14 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1133: added missing ConfigureAwait(false) calls to prevent deadlocks.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f72da0dc417e720ffb7dc644331dfe41e6b484f4

Generated at Wed Feb 07 21:38:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.