[CSHARP-4114] Hang opening new async cursor Created: 28/Mar/22  Updated: 27/Oct/23  Resolved: 22/Apr/22

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

Type: Bug Priority: Major - P3
Reporter: Marc Simkin Assignee: Dmitry Lukyanov (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive dump_20220328_095844.zip     Zip Archive dump_20220328_095900.zip     Zip Archive dump_20220328_095940.zip     Zip Archive dump_20220328_100311.zip     Zip Archive dump_20220328_100416.zip     Zip Archive dump_20220328_100535.zip     Zip Archive dump_20220328_100638.zip    

 Description   

Application Info:

Target Framework: .NET 6,

Project Type: Blazor Server Side, Microsoft.NET.Sdk.Web

Summary

Similar issue to CSHARP-3477

When I open an Async Cursor, the application hangs.

I have determined it is the opening of the cursor, if I use code like this:

using var cursor = await _collection.FindAsync(query, options, token);
 
while (await cursor.MoveNextAsync(token))
     loopProcessor(cursor.Current);

If I change the call to be:

await _collection.FindAsync(query, options, token).ToList();

Everything works as expected.

All this code is in a repository class that lives in an internally developed library and is used across several applications.  The only application that hangs is the Blazor Server Side app.

I have not been able to duplicate this issue in any other code.  It happens consistently in the Blazor app always on the same line of code. Here is the code that calls the repository class:

private List<Product> GetProductData(FilterDefinition<Product> filter)
{
    IEnumerable<Product>? productList = null;
    IEnumerable<Product>? partialProductList = null;
 
    System.Diagnostics.Debug.WriteLine("Process Id = {0}.", System.Diagnostics.Process.GetCurrentProcess().Id);
 
    var productListTask = _productService.GetItemsFromMongoAsync(filter, new FindOptions<Product, Product>());
    var partialProductListTask = _partialProductService.GetItemsFromMongoAsync(filter, new FindOptions<Product, Product>());
 
    Task.WaitAll(productListTask, partialProductListTask);
 
    if (partialProductListTask.IsCompletedSuccessfully)
        partialProductList = partialProductListTask.Result;
 
    if (productListTask.IsCompletedSuccessfully)
        productList = productListTask.Result;
 
    if (productList is not null && partialProductList is not null)
        return productList.Union(partialProductList).Distinct().OrderBy(a => a.Ean).ToList();
    else if (productList is not null && partialProductList is null)
        return productList.ToList();
    else if (productList is null && partialProductList is not null)
        return partialProductList.ToList();
    return new List<Product>();
}

I have attached several dump files. The dump file that ends in 095844 is immediately before the call to mongo.  All the other files are after the app has hung.

 

 



 Comments   
Comment by PM Bot [ 22/Apr/22 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Dmitry Lukyanov (Inactive) [ 07/Apr/22 ]

I think this behavior is related to missed "ConfigureAwait(false)" for async methods that you wait. Can you try updating all async methods you have in similar way:

_productService.GetItemsFromMongoAsync(filter, new FindOptions<Product, Product>()).ConfigureAwait(false);

Comment by Marc Simkin [ 04/Apr/22 ]

@Dmitry Lukyanov, 2.15 against a 5.0.5 non-sharded, non-clustered environment has the same issue.  The 5.0.5 server is running on my development workstation (ie.: localhost).

Comment by Dmitry Lukyanov (Inactive) [ 04/Apr/22 ]

Hey msimkin@bn.com , thanks for your report, we will look at this and come back to you. Meanwhile, can you check this behavior with the latest 2.15 release?

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