Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge amount of TaskCanceledException being logged #26884

Closed
Liero opened this issue Dec 3, 2021 · 2 comments
Closed

Huge amount of TaskCanceledException being logged #26884

Liero opened this issue Dec 3, 2021 · 2 comments

Comments

@Liero
Copy link

Liero commented Dec 3, 2021

File a bug

I have a virtual scrolling listbox, where items are loaded from DB on demand.

As user scrolls, the previous requests are cancelled using CancellationToken, that is passed to IQueryable.ToArrayAsync(), resp CountAsync(); methods

This produces tons of exceptions being logged using ILogger:

fail: Microsoft.EntityFrameworkCore.Query[10100]
      An exception occurred while iterating over the results of a query for context type 'Domain.Manufacture.ManufactureDbContext'.
      System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
      System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()

I think it should not log the exception with LogLever=Error, as this is expected exception

This is bloats my logs with useful messages. I believe that expected exception should not be logger as Errors.

Would you consider changing LogLevel to Info, or Debug?

Include your code

private async ValueTask<ItemsProviderResult<Employee>> LoadEmployees(
    ItemsProviderRequest request)
{
    using var dbContext = DbContextFactory.CreateDbContext();
    var query = dbContext.MaterialsView.AsNoTracking()
       .OrderBy(e => e.Id);

    try {
            var items = await query.Skip(request.StartIndex).Take(request.Count)
               .ToArrayAsync(request.CancellationToken);
           var count = await query.CountAsync(request.CancellationToken);
           return new ItemsProviderResult<Employee>(items, count);
    }
    catch (TaskCanceledException) {
        // Don't log
        return default;
    }
}

Include provider and version information

EF Core version: 6.0
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 6.0)
Operating system:
IDE: (e.g. Visual Studio 2022 17.0)

dotnet --info
.NET SDK (reflecting any global.json):
Version:   6.0.100
Commit:    9e8b04bbff

Runtime Environment:
OS Name:     Windows
OS Version:  10.0.22000
OS Platform: Windows
RID:         win10-x64
Base Path:   C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support):
 Version: 6.0.0
 Commit:  4822e3c3aa
@roji
Copy link
Member

roji commented Dec 3, 2021

Duplicate of #19526

@roji roji marked this as a duplicate of #19526 Dec 3, 2021
@roji
Copy link
Member

roji commented Dec 3, 2021

@Liero we're planning to allow filtering out log messages for cancellation in EF Core 7.0 (or otherwise manage them differently).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants