couchbaselabs / Linq2Couchbase

A Language Integrated Query (LINQ) provider for the Couchbase .NET SDK
Apache License 2.0
95 stars 46 forks source link

Async queries runs synchronous in .net 4.8 #369

Closed mdegroux closed 11 months ago

mdegroux commented 11 months ago

Hi, using this code:

    IQueryable<Cibml> query = context.Query<Cibml>().Where(c => c.tradeId >= 1000000 && c.tradeId <= 10001000);
    IAsyncEnumerable<Cibml> enumearble = query.ToAsyncEnumerable();
    IAsyncEnumerator<Cibml> enumerator = enumearble.GetAsyncEnumerator(cts.Token);

    while (await enumerator.MoveNextAsync())
    {
        Console.WriteLine($"Received trade " + enumerator.Current.tradeId);

    }

In .net 7.0 enumeration starts before the query ends (this is expected) In .net 4.8, enumeration starts after the query ends

Best regards

brantburnett commented 11 months ago

This is actually a limitation of the Couchbase SDK itself, rather than the LINQ library. The HTTP request to the query service is running with HttpCompletionOption.ResponseContentRead in .NET 4 whereas it runs with HttpCompletionOption.ResponseHeadersRead in modern .NET. An effort was made a few months back to use ResponseHeadersRead in .NET 4 but implementation differences under the hood in .NET caused sporadic exceptions in that case.

Here is the issue for the original change: https://issues.couchbase.com/browse/NCBC-3382 And here is the issue where it was reverted for .NET 4 only: https://issues.couchbase.com/browse/NCBC-3433