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

Check how EF7 handles task cancellations #1040

Closed
Stra1ghter opened this issue Oct 7, 2022 · 16 comments · Fixed by #1084
Closed

Check how EF7 handles task cancellations #1040

Stra1ghter opened this issue Oct 7, 2022 · 16 comments · Fixed by #1084
Milestone

Comments

@Stra1ghter
Copy link

Which version of Duende IdentityServer are you using?
6.1.5
Which version of .NET are you using?
net6.0

Describe the bug

When a user cancels a browser request that is handled by IdentityServerMiddleware the TaskCanceledException is logged as a critical log. We see the errors in different stack traces, but it is always a task that finally queries some store via EF Core.

To Reproduce

I couldn't absolutely reproduce the behaviour, but it seems to be known.
This usually always happens when you accept a CancellationToken in your actions, e.g. for long running operations, but don't handle the cancellation of the task.

Please note that it's now possible in EF Core to distinguish between cancellation and failure.

Expected behavior

Handle user caused task cancellations (e.g. clicking stop or refresh in the browser) by a custom filter, that could log this as information or debug.

Another solution would be to simply stop accepting and passing CancellationToken on IdentityServer's actions. I don't think IdentityServer has long running tasks that would benefit from knowing about the cancellation of a task, but I might be wrong here.

Log output/exception with stacktrace

Unhandled exception: "A task was canceled."
A task was canceled.
TaskCanceledExceptionSystem.Private.CoreLib   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant token) in /_/src/EntityFramework.Storage/Stores/PersistedGrantStore.cs:line 59
   at Duende.IdentityServer.Stores.DefaultGrantStore`1.StoreItemByHashedKeyAsync(String hashedKey, T item, String clientId, String subjectId, String sessionId, String description, DateTime created, Nullable`1 expiration, Nullable`1 consumedTime) in /_/src/IdentityServer/Stores/Default/DefaultGrantStore.cs:line 227
   at Duende.IdentityServer.Stores.DefaultGrantStore`1.CreateItemAsync(T item, String clientId, String subjectId, String sessionId, String description, DateTime created, Int32 lifetime) in /_/src/IdentityServer/Stores/Default/DefaultGrantStore.cs:line 173
   at Duende.IdentityServer.Stores.DefaultRefreshTokenStore.StoreRefreshTokenAsync(RefreshToken refreshToken) in /_/src/IdentityServer/Stores/Default/DefaultRefreshTokenStore.cs:line 43
   at Duende.IdentityServer.Services.DefaultRefreshTokenService.CreateRefreshTokenAsync(RefreshTokenCreationRequest request) in /_/src/IdentityServer/Services/Default/DefaultRefreshTokenService.cs:line 211
   at Duende.IdentityServer.ResponseHandling.TokenResponseGenerator.CreateAccessTokenAsync(ValidatedTokenRequest request) in /_/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs:line 508
   at Duende.IdentityServer.ResponseHandling.TokenResponseGenerator.ProcessAuthorizationCodeRequestAsync(TokenRequestValidationResult request) in /_/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs:line 149
   at Duende.IdentityServer.ResponseHandling.TokenResponseGenerator.ProcessAsync(TokenRequestValidationResult request) in /_/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs:line 100
   at Duende.IdentityServer.Endpoints.TokenEndpoint.ProcessTokenRequestAsync(HttpContext context) in /_/src/IdentityServer/Endpoints/TokenEndpoint.cs:line 109
   at Duende.IdentityServer.Endpoints.TokenEndpoint.ProcessAsync(HttpContext context) in /_/src/IdentityServer/Endpoints/TokenEndpoint.cs:line 76
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordi

Stack trace is trimmed due to the fact that it exceeds maximum number of characters.

@brockallen
Copy link
Member

Yea, now with EF7 we can look to see what they have actually changed. I thought they promised that this would no longer be a thrown exception. I was hoping it'd just stop being an exception and they would just log instead. But maybe that's not what they ended up doing (which would be unfortunate).

@brockallen brockallen transferred this issue from DuendeSoftware/Support Oct 7, 2022
@brockallen brockallen changed the title Task cancellations are logged as critical Check how EF7 handles task cancellations Oct 7, 2022
@brockallen brockallen added this to the 6.2.0 milestone Oct 7, 2022
@brockallen
Copy link
Member

brockallen commented Nov 1, 2022

Maybe I'm doing something wrong, but these look the same to me. Oh, ok... I guess the error that the Query class emitted is now gone. But the rest are still there (mainly due to being thrown?). Not sure if this really helps anything.

.NET 6

[15:35:11 Debug] Duende.IdentityServer.Endpoints.DiscoveryEndpoint
Start discovery request

[15:35:12 Error] Microsoft.EntityFrameworkCore.Database.Connection
An error occurred using the connection to database 'Duende.EntityFramework-6.1.0' on server '(localdb)\mssqllocaldb'.

[15:35:12 Error] Microsoft.EntityFrameworkCore.Query
An exception occurred while iterating over the results of a query for context type 'Duende.IdentityServer.EntityFramework.DbContexts.PersistedGrantDbContext'.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()

[15:35:12 Fatal] Duende.IdentityServer.Hosting.IdentityServerMiddleware
Unhandled exception: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.SigningKeyStore.LoadKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\EntityFramework.Storage\Stores\SigningKeyStore.cs:line 64
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysFromStoreAsync(Boolean cache) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 428
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysInternalAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 108
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 95
   at Duende.IdentityServer.Services.KeyManagement.AutomaticKeyManagerKeyStore.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\AutomaticKeyManagerKeyStore.cs:line 105
   at Duende.IdentityServer.Services.DefaultKeyMaterialService.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\DefaultKeyMaterialService.cs:line 112
   at Duende.IdentityServer.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\ResponseHandling\Default\DiscoveryResponseGenerator.cs:line 109
   at Duende.IdentityServer.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Endpoints\DiscoveryEndpoint.cs:line 65
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 98

[15:35:12 Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware
An unhandled exception has occurred while executing the request.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.SigningKeyStore.LoadKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\EntityFramework.Storage\Stores\SigningKeyStore.cs:line 64
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysFromStoreAsync(Boolean cache) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 428
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysInternalAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 108
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 95
   at Duende.IdentityServer.Services.KeyManagement.AutomaticKeyManagerKeyStore.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\AutomaticKeyManagerKeyStore.cs:line 105
   at Duende.IdentityServer.Services.DefaultKeyMaterialService.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\DefaultKeyMaterialService.cs:line 112
   at Duende.IdentityServer.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\ResponseHandling\Default\DiscoveryResponseGenerator.cs:line 109
   at Duende.IdentityServer.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Endpoints\DiscoveryEndpoint.cs:line 65
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 98
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 113
   at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\MutualTlsEndpointMiddleware.cs:line 94
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\DynamicProviders\DynamicSchemes\DynamicSchemeAuthenticationMiddleware.cs:line 47
   at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\BaseUrlMiddleware.cs:line 27
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

[15:35:12 Debug] Serilog.AspNetCore.RequestLoggingMiddleware
HTTP GET /.well-known/openid-configuration responded 500 in 4680.4340 ms

.NET 7

[15:29:27 Debug] Duende.IdentityServer.Endpoints.DiscoveryEndpoint
Start discovery request

[15:29:28 Error] Microsoft.EntityFrameworkCore.Database.Connection
An error occurred using the connection to database 'Duende.EntityFramework-6.1.0' on server '(localdb)\mssqllocaldb'.

[15:29:28 Fatal] Duende.IdentityServer.Hosting.IdentityServerMiddleware
Unhandled exception: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.SigningKeyStore.LoadKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\EntityFramework.Storage\Stores\SigningKeyStore.cs:line 64
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysFromStoreAsync(Boolean cache) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 428
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysInternalAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 108
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 95
   at Duende.IdentityServer.Services.KeyManagement.AutomaticKeyManagerKeyStore.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\AutomaticKeyManagerKeyStore.cs:line 105
   at Duende.IdentityServer.Services.DefaultKeyMaterialService.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\DefaultKeyMaterialService.cs:line 112
   at Duende.IdentityServer.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\ResponseHandling\Default\DiscoveryResponseGenerator.cs:line 109
   at Duende.IdentityServer.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Endpoints\DiscoveryEndpoint.cs:line 65
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 98

[15:29:28 Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware
An unhandled exception has occurred while executing the request.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.SigningKeyStore.LoadKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\EntityFramework.Storage\Stores\SigningKeyStore.cs:line 64
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysFromStoreAsync(Boolean cache) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 428
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysInternalAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 108
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 95
   at Duende.IdentityServer.Services.KeyManagement.AutomaticKeyManagerKeyStore.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\AutomaticKeyManagerKeyStore.cs:line 105
   at Duende.IdentityServer.Services.DefaultKeyMaterialService.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\DefaultKeyMaterialService.cs:line 112
   at Duende.IdentityServer.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\ResponseHandling\Default\DiscoveryResponseGenerator.cs:line 109
   at Duende.IdentityServer.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Endpoints\DiscoveryEndpoint.cs:line 65
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 98
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 113
   at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\MutualTlsEndpointMiddleware.cs:line 94
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\DynamicProviders\DynamicSchemes\DynamicSchemeAuthenticationMiddleware.cs:line 47
   at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\BaseUrlMiddleware.cs:line 27
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

[15:29:28 Debug] Serilog.AspNetCore.RequestLoggingMiddleware
HTTP GET /.well-known/openid-configuration responded 500 in 6207.1057 ms

@brockallen
Copy link
Member

Oh, ok... I guess the error that the Query class emitted is now gone. But the rest are still there (mainly due to being thrown?). Not sure if this really helps anything.

So then for @Stra1ghter -- we are still getting an unhandled exception in the IdentityServerMiddleware. If we ignore this, then the host still gets this:

[15:47:56 Debug] Duende.IdentityServer.Endpoints.DiscoveryEndpoint
Start discovery request

[15:47:57 Error] Microsoft.EntityFrameworkCore.Database.Connection
An error occurred using the connection to database 'Duende.EntityFramework-6.1.0' on server '(localdb)\mssqllocaldb'.

[15:47:57 Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware
An unhandled exception has occurred while executing the request.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.SigningKeyStore.LoadKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\EntityFramework.Storage\Stores\SigningKeyStore.cs:line 64
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysFromStoreAsync(Boolean cache) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 428
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysInternalAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 108
   at Duende.IdentityServer.Services.KeyManagement.KeyManager.GetAllKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\KeyManager.cs:line 95
   at Duende.IdentityServer.Services.KeyManagement.AutomaticKeyManagerKeyStore.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\KeyManagement\AutomaticKeyManagerKeyStore.cs:line 105
   at Duende.IdentityServer.Services.DefaultKeyMaterialService.GetValidationKeysAsync() in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Services\Default\DefaultKeyMaterialService.cs:line 112
   at Duende.IdentityServer.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\ResponseHandling\Default\DiscoveryResponseGenerator.cs:line 109
   at Duende.IdentityServer.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Endpoints\DiscoveryEndpoint.cs:line 65
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\IdentityServerMiddleware.cs:line 98
   at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\MutualTlsEndpointMiddleware.cs:line 94
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\DynamicProviders\DynamicSchemes\DynamicSchemeAuthenticationMiddleware.cs:line 47
   at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in C:\ballen\work\Duende\github\IdentityServer\src\IdentityServer\Hosting\BaseUrlMiddleware.cs:line 27
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

[15:47:57 Debug] Serilog.AspNetCore.RequestLoggingMiddleware
HTTP GET /.well-known/openid-configuration responded 500 in 3809.9713 ms

So... then I'm not sure what's better? I guess it's still one less log entry. Thoughts?

@Stra1ghter
Copy link
Author

@brockallen the remaining logs stem from SqlClient, right? Reading roji's answer in the issue, I thought that this is fixed with SqlClient as well, but according to #26988 this is not the case.

In case your middleware actions need to accept CancellationToken s, then I guess we have to wait for a "real" fix in SqlClient.
Adding a filter to your middleware in general would be problematic.
Thoughts:

  • Update to EFCore 7 when you would usually do.
  • (Maybe) provide a documented middleware that we as IdentityServer users can use to filter out those messages. I could also understand if you choose to not offer this as it is duck tape around issues that are not in your control. On the other hand, we have a solution that is randomly logging critical errors during normal operations.

@brockallen
Copy link
Member

brockallen commented Nov 2, 2022

the remaining logs stem from SqlClient, right?

I believe yes, this line:

[15:47:57 Error] Microsoft.EntityFrameworkCore.Database.Connection

Update to EFCore 7 when you would usually do.

Yep, 6.2 is our release for targeting .NET 7.

In case your middleware actions need to accept CancellationToken

Where? I just tried and the DI system is not happy. I was thinking we could just look at the HttpContext's RequestAborted.

Adding a filter to your middleware in general would be dotnet/efcore#19526 (comment).

Why? Why not simply suppress our log entry if the exception is a TaskCanceledException and RequestAborted.IsCancellationRequested is true?

So in other words -- we still have 2 log entries to deal with. One from MS we can't do anything about, but the one from IS we can.

Currently our middleware does this:

catch (Exception ex)
        {
            await events.RaiseAsync(new UnhandledExceptionEvent(ex));
            _logger.LogCritical(ex, "Unhandled exception: {exception}", ex.Message);
            throw;
        }

But I was thinking something like this:

catch (Exception ex) when (ex is not TaskCanceledException && !context.RequestAborted.IsCancellationRequested)
        {
            await events.RaiseAsync(new UnhandledExceptionEvent(ex));
            _logger.LogCritical(ex, "Unhandled exception: {exception}", ex.Message);
            throw;
        }

@Stra1ghter
Copy link
Author

Where? I just tried and the DI system is not happy. I was thinking we could just look at the HttpContext's RequestAborted.

Well, correct me if I'm wrong (I'm not a full time ASP.NET Core guy), but CancellationTokens in ASP.NET Core have the purpose to stop expensive non-mutating operations. My first thought was, that you don't need this?

Example: you use your own ICancellationTokenProvider that will end up providing HttpContext.RequestAborted. In your EFCore ClientStore implementation, you provide the token to the IQueryable.ToArrayAsync, this is basically saying EFCore "throw if the token indicates a cancelation". This is beneficial for long running, expensive operations, because you could stop before doing additional work.
But in this case the query has already been issued and will be reaching SQL Server anyway and I couldn't see any other expensive operations. (Again, I don't know your codebase in-depth so I might be wrong here.)

If you would not provide a CancellationToken to ToArrayAsync, EFCore wouldn't care about the cancelation. (Identity Server would still work on an aborted request, but I don't think that matters as it doesn't perform batch operations?)

Why? Why not simply suppress our log entry if the exception is a TaskCanceledException and RequestAborted.IsCancellationRequested is true?

The more I think about it, the more my feelings say that you should do this. You use the tokens and don't do anything with the exception. You could in fact also catch TaskCanceledException and log it as information. We will still see the SqlClient errors, but that is nothing you can do anything about (except not using CancellationTokens altogether).

@brockallen
Copy link
Member

@Stra1ghter PR has been submitted to allow flexibility here. Please have a look.

@jonathanhallee
Copy link

Hello,

Sorry to comment on this closed issue.

I have went down the rabbit hole of github issues related to this in the efcore repo.

Judging from the response I read from @Stra1ghter there is no way for us to avoid one of the TaskCanceledExceptions coming out of the SqlClient?

We just updated to 6.2.1 and I can see the exception handler you added in the LoggingOptions allows us to remove one of both as stated. We tried migrating to .NET 7 (Including our deps to EF Core 7) as I thought it would partially resolve but it doesn't seem like it?

@Liero
Copy link

Liero commented Jan 31, 2023

@Stra1ghter:

But in this case the query has already been issued and will be reaching SQL Server anyway and I couldn't see any other expensive operations. (Again, I don't know your codebase in-depth so I might be wrong here.)

There is bunch of opportunities where the CancellationToken can cancel already issued query -> When opening connection, waiting for connection pool or even while reading data - just to name few.

In general, you should not log expected exception as critical - When you cancel a request using cancellation token, then some exception is expected.

@pampua84
Copy link

Hello,
sorry if I post in this closed thread, but I have a doubt, in case the value is:

CancellationRequested: false

is possible to ignore the exception or is the error due to some other problem?
I post the stack for completeness:

System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Duende.IdentityServer.EntityFramework.Stores.ClientStore.FindClientByIdAsync(String clientId) in /_/src/EntityFramework.Storage/Stores/ClientStore.cs:line 87
   at Duende.IdentityServer.Stores.ValidatingClientStore`1.FindClientByIdAsync(String clientId) in /_/src/IdentityServer/Stores/ValidatingClientStore.cs:line 76
   at Duende.IdentityServer.Stores.IClientStoreExtensions.FindEnabledClientByIdAsync(IClientStore store, String clientId) in /_/src/IdentityServer/Extensions/IClientStoreExtensions.cs:line 27
   at Duende.IdentityServer.Validation.AuthorizeRequestValidator.LoadClientAsync(ValidatedAuthorizeRequest request) in /_/src/IdentityServer/Validation/Default/AuthorizeRequestValidator.cs:line 228
   at Duende.IdentityServer.Validation.AuthorizeRequestValidator.ValidateAsync(NameValueCollection parameters, ClaimsPrincipal subject) in /_/src/IdentityServer/Validation/Default/AuthorizeRequestValidator.cs:line 146
   at Duende.IdentityServer.Services.OidcReturnUrlParser.ParseAsync(String returnUrl) in /_/src/IdentityServer/Services/Default/OidcReturnUrlParser.cs:line 67
   at Duende.IdentityServer.Services.ReturnUrlParser.ParseAsync(String returnUrl) in /_/src/IdentityServer/Services/Default/ReturnUrlParser.cs:line 46
   at Duende.IdentityServer.Services.DefaultIdentityServerInteractionService.GetAuthorizationContextAsync(String returnUrl) in /_/src/IdentityServer/Services/Default/DefaultIdentityServerInteractionService.cs:line 68

@brockallen
Copy link
Member

is possible to ignore the exception or is the error due to some other problem?

You can wrap our middleware in your own try/catch and control that any way you want.

@pampua84
Copy link

Hi, maybe my question wasn't very clear, since the task cancellation is not requested, this type of exception is still a false positive and therefore I don't have to worry or is it a problem with my application/database and I have to investigate what? Thank you

@brockallen
Copy link
Member

Oh I see -- so you're getting this exception but the request was not cancelled by the caller? In that case, I'm not sure -- do you have more details of the exception?

@pampua84
Copy link

Here is the entire exception log:

{
    "@t": "2023-03-23T11:59:42.0082567Z",
    "@mt": "An unhandled exception has occurred while executing the request.",
    "@l": "Error",
    "@x": "System.Threading.Tasks.TaskCanceledException: A task was canceled.\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()\r\n   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)\r\n   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)\r\n   at Duende.IdentityServer.EntityFramework.Stores.ClientStore.FindClientByIdAsync(String clientId) in /_/src/EntityFramework.Storage/Stores/ClientStore.cs:line 87\r\n   at Duende.IdentityServer.Stores.ValidatingClientStore`1.FindClientByIdAsync(String clientId) in /_/src/IdentityServer/Stores/ValidatingClientStore.cs:line 76\r\n   at Duende.IdentityServer.Stores.IClientStoreExtensions.FindEnabledClientByIdAsync(IClientStore store, String clientId) in /_/src/IdentityServer/Extensions/IClientStoreExtensions.cs:line 27\r\n   at Duende.IdentityServer.Validation.AuthorizeRequestValidator.LoadClientAsync(ValidatedAuthorizeRequest request) in /_/src/IdentityServer/Validation/Default/AuthorizeRequestValidator.cs:line 228\r\n   at Duende.IdentityServer.Validation.AuthorizeRequestValidator.ValidateAsync(NameValueCollection parameters, ClaimsPrincipal subject) in /_/src/IdentityServer/Validation/Default/AuthorizeRequestValidator.cs:line 146\r\n   at Duende.IdentityServer.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, Boolean checkConsentResponse) in /_/src/IdentityServer/Endpoints/AuthorizeEndpointBase.cs:line 153\r\n   at Duende.IdentityServer.Endpoints.AuthorizeCallbackEndpoint.ProcessAsync(HttpContext context) in /_/src/IdentityServer/Endpoints/AuthorizeCallbackEndpoint.cs:line 55\r\n   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IdentityServerOptions options, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in /_/src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 121\r\n   at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in /_/src/IdentityServer/Hosting/MutualTlsEndpointMiddleware.cs:line 95\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n   at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/DynamicProviders/DynamicSchemes/DynamicSchemeAuthenticationMiddleware.cs:line 48\r\n   at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/BaseUrlMiddleware.cs:line 28\r\n   at UI.Middlewares.SamlProxyMiddleware.InvokeAsync(HttpContext context) in C:\\AG1_v2.165.0\\_work\\711\\s\\src\\Web\\UI\\Middlewares\\SamlProxyMiddleware.cs:line 42\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at UI.Middlewares.NotFoundMiddleware.InvokeAsync(HttpContext context) in C:\\AG1_v2.165.0\\_work\\711\\s\\src\\Web\\UI\\Middlewares\\NotFoundMiddleware.cs:line 22\r\n   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)",
    "EventId": {
        "Id": 1,
        "Name": "UnhandledException"
    },
    "SourceContext": "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware",
    "RequestId": "80000a0c-0001-dd00-b63f-84710c7967bb",
    "RequestPath": "/connect/authorize/callback",
    "ExceptionDetail": {
        "Type": "System.Threading.Tasks.TaskCanceledException",
        "HResult": -2146233029,
        "Message": "A task was canceled.",
        "Source": "System.Private.CoreLib",
        "TargetSite": "Void ThrowForNonSuccess(System.Threading.Tasks.Task)",
        "CancellationToken": "CancellationRequested: false",
        "Task": {
            "Id": 6,
            "Status": "Canceled",
            "CreationOptions": "None"
        }
    }
}

@brockallen
Copy link
Member

brockallen commented Mar 23, 2023

Well... all that shows is that the cancellation token that was passed into the EF layer was triggered. Unless you did anything special, then it's ASP.NET doing it due to some reason. We did make the filter (UnhandledExceptionLoggingFilter) we use extensible so you can look closer at the exception and decide if you want to ignore it or not:

https://docs.duendesoftware.com/identityserver/v6/reference/options/#logging

@pampua84
Copy link

Thanks, I'll try to investigate and understand the problem.

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