Base solution for your next web application
Open Closed

exception when impersonating tenant user #8611


User avatar
0
alexanderpilhar created

8.2.1, Angular, .Net Core

Sometimes, when impersonating as a tenant user, an exception is thrown (...pZeroTemplate.Web.Core/Authentication/JwtBearer/AbpZeroTemplateJwtSecurityTokenHandler.cs):

Log.txt:

ERROR 2020-02-28 14:19:06,679 [44   ] Mvc.ExceptionHandling.AbpExceptionFilter - A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, 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.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.FirstOrDefaultAsync(TPrimaryKey id)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at CompanyName.ProjectName.Authorization.Users.UserManager.GetUserOrNullAsync(UserIdentifier userIdentifier) in D:\UserName\source\repos\CompanyName.ProjectName.Core\src\CompanyName.ProjectName.Core\Authorization\Users\UserManager.cs:line 84
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at CompanyName.ProjectName.Authorization.Users.UserManager.GetUserAsync(UserIdentifier userIdentifier) in D:\UserName\source\repos\CompanyName.ProjectName.Core\src\CompanyName.ProjectName.Core\Authorization\Users\UserManager.cs:line 95
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
   at Nito.AsyncEx.AsyncContext.<>c__DisplayClass16_0`1.&lt;Run&gt;b__0(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
   at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
   at Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func)
   at CompanyName.ProjectName.Authorization.Users.UserManager.GetUser(UserIdentifier userIdentifier) in D:\UserName\source\repos\CompanyName.ProjectName.Core\src\CompanyName.ProjectName.Core\Authorization\Users\UserManager.cs:line 106
   at CompanyName.ProjectName.Web.Controllers.TokenAuthController.LogOut() in D:\UserName\source\repos\CompanyName.ProjectName.Core\src\CompanyName.ProjectName.Web.Core\Controllers\TokenAuthController.cs:line 268
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeInnerFilterAsync&gt;g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextExceptionFilterAsync&gt;g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)


Further information:

  • I'm experiencing this issue since version 8.2.1 (upgraded from 8.1.0) in my development environment (did not try in production yet).
  • Sometimes, it also occurs when switching back from tenant user account to host user account.
  • It usually only occurs on first time impersonating a specific tenant user, after that there is no problem anymore until i completely restart the application.

Can anybody confirm this behaviour?

EDIT


I did also implement changes according to remove unused codes but it did not change the behaviour.


19 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    According to the logs, the problem seems to occur at the time of LogOut(TokenAuthController). right?

  • User Avatar
    0
    rickfrankel created

    I'm seeing this a lot as well. We see it a lot in this space as well. This happens a lot with switching accounts through the manage linked accounts bit or with the impersonation function.

    Agree with alexanderpilhar we have only started seeing this since the upgrade to 8.2.1. Also this is happening in our production environment.

    at System.Threading.CancellationToken.ThrowOperationCanceledException()
    at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList`1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\CommandExecutor.cs:line 20
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
    at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
    at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
    at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.FirstOrDefaultAsync(TPrimaryKey id)
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
    at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location where exception was thrown ---
    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp; currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location where exception was thrown ---
    at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
    at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
    at XXXX.Friendships.Cache.UserFriendsCache.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\Cache\UserFriendsCache.cs:line 195
    at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal_callback(UserIdentifier userIdentifier)
    at Castle.Proxies.Invocations.UserFriendsCache_GetUserFriendsCacheItemInternal.InvokeMethodOnTarget()
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier)
    at XXXX.Friendships.Cache.UserFriendsCache.&lt;&gt;c__DisplayClass8_0.&lt;GetCacheItem&gt;b__0(String f) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\Cache\UserFriendsCache.cs:line 46
    at Abp.Runtime.Caching.CacheExtensions.&lt;&gt;c__DisplayClass5_0`2.&lt;Get&gt;b__0(String k)
    at Abp.Runtime.Caching.AbpCacheBase`2.Get(TKey key, Func`2 factory)
    at Abp.Runtime.Caching.CacheExtensions.Get[TKey,TValue](ICache cache, TKey key, Func`2 factory)
    at Castle.Proxies.Invocations.UserFriendsCache_GetCacheItem.InvokeMethodOnTarget()
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Castle.Proxies.UserFriendsCacheProxy.GetCacheItem(UserIdentifier userIdentifier)
    at XXXX.Friendships.ChatUserStateWatcher.NotifyUserConnectionStateChange(UserIdentifier user, Boolean isConnected) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\ChatUserStateWatcher.cs:line 45
    at XXXX.Friendships.ChatUserStateWatcher.OnlineClientManager_UserDisconnected(Object sender, OnlineUserEventArgs e) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\ChatUserStateWatcher.cs:line 41
    at Abp.RealTime.OnlineClientManager.Remove(String connectionId)
    at Abp.AspNetCore.SignalR.Hubs.OnlineClientHubBase.OnDisconnectedAsync(Exception exception)
    System.OperationCanceledException: The operation was canceled.
    at System.Threading.CancellationToken.ThrowOperationCanceledException()
    at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList`1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\CommandExecutor.cs:line 20
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
    at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
    at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
    at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
    at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.FirstOrDefaultAsync(TPrimaryKey id)
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
    at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location where exception was thrown ---
    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp; currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location where exception was thrown ---
    at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
    at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
    at XXXX.Friendships.Cache.UserFriendsCache.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\Cache\UserFriendsCache.cs:line 195
    at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal_callback(UserIdentifier userIdentifier)
    at Castle.Proxies.Invocations.UserFriendsCache_GetUserFriendsCacheItemInternal.InvokeMethodOnTarget()
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier)
    at XXXX.Friendships.Cache.UserFriendsCache.&lt;&gt;c__DisplayClass8_0.&lt;GetCacheItem&gt;b__0(String f) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\Cache\UserFriendsCache.cs:line 46
    at Abp.Runtime.Caching.CacheExtensions.&lt;&gt;c__DisplayClass5_0`2.&lt;Get&gt;b__0(String k)
    at Abp.Runtime.Caching.AbpCacheBase`2.Get(TKey key, Func`2 factory)
    at Abp.Runtime.Caching.CacheExtensions.Get[TKey,TValue](ICache cache, TKey key, Func`2 factory)
    at Castle.Proxies.Invocations.UserFriendsCache_GetCacheItem.InvokeMethodOnTarget()
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
    at Castle.DynamicProxy.AbstractInvocation.Proceed()
    at Castle.Proxies.UserFriendsCacheProxy.GetCacheItem(UserIdentifier userIdentifier)
    at XXXX.Friendships.ChatUserStateWatcher.NotifyUserConnectionStateChange(UserIdentifier user, Boolean isConnected) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\ChatUserStateWatcher.cs:line 45
    at XXXX.Friendships.ChatUserStateWatcher.OnlineClientManager_UserDisconnected(Object sender, OnlineUserEventArgs e) in D:\a\1\s\aspnet-core\src\XXXX.Core\Friendships\ChatUserStateWatcher.cs:line 41
    at Abp.RealTime.OnlineClientManager.Remove(String connectionId)
    at Abp.AspNetCore.SignalR.Hubs.OnlineClientHubBase.OnDisconnectedAsync(Exception exception)
    
  • User Avatar
    0
    alexanderpilhar created

    @maliming sorry, I can't tell for sure. If the process of impersonation involves a logout ... I just can't tell.

    But heres another Log.txt that involves the following:

    • Login as host user
    • Logout
    • Login as host user
    • Impersonate tenant A user A.1 => exception
    • Back to host user
    • Impersonate tenant A user A.1 again => no exception
    • Back to host user
    • Impersonate tenant B user B.1 => exception
    • Back to host user
    • Impersonate tenant C user C.1 => exception
    • Back to host user
    • Impersonate tenant B user B.1 => no exception
    • Back to host user
    • Impersonate tenant C user C.1 => no exception
    • Back to host user
    • Impersonate tenant A user A.1 => no exception
    • Back to host user
    • Logout

    Log.txt: 20200303-Log.txt

  • User Avatar
    0
    alexanderpilhar created

    The exception also occurs when selecting another user of a specific tenant for impersonation, e.g.:

    • Impersonate tenant A user A.1 => exception
    • Impersonate tenant A user A.2 => exception
    • Impersonate tenant A user A.1 again => no exception
    • Impersonate tenant A user A.2 again => no exception
  • User Avatar
    0
    maliming created
    Support Team

    hi @alexanderpilhar

    Can you see if the request was cancelled in the network panel of the browser?

  • User Avatar
    0
    alexanderpilhar created

    @maliming no, the request has not been canceled.

    FYI: After login, I'm not routing to the dashboard that comes with ASPNETZERO but to a custom component (which is a default feature but also needs permission) - could this have something to do with the exception thrown?

  • User Avatar
    0
    maliming created
    Support Team

    hi @alexanderpilhar

    Can you try the code below?

    public override void PreInitialize()
    {
          Configuration.ReplaceService<ICancellationTokenProvider, NullCancellationTokenProvider>(DependencyLifeStyle.Transient);
    }
    
  • User Avatar
    0
    alexanderpilhar created

    @maliming where do i have to place this code? PreInitialize() of which module?

    EDIT:

    I placed it at the end of PreInitialize() in core-module - the exception is gone!

    But what does it mean? Is this the solution you suggest? Are there any other implications with this? Or will this work fine?

  • User Avatar
    0
    maliming created
    Support Team

    @alexanderpilhar

    I don't think this exception will affect your application. Currently it just appears in the log, right?

  • User Avatar
    0
    alexanderpilhar created

    @maliming actually, the exception doesn't seem to affect the application anywhere but in my development environment - and there I can simply click continue. Nothing bad seems to happen.

    I already have it in production but I can't tell if it occurs there as well, since I don't have logs working in production environment yet (IIS, self hosted). It seems the application just continues to work as well.

    So, yes, you are right - it might not affect the application in any bad way. But, should I remove the suggested code or should I keep it (I guess, you just wanted me to test something, right)?

  • User Avatar
    0
    rickfrankel created

    @maliming I'll also test out you config option. we have noted this a lot in our production environment but you are right it hasn't caused any actual issue other than filling our logs.

    cheers

  • User Avatar
    2
    maliming created
    Support Team

    hi @alexanderpilhar @rickfrankel

    Because abp uses HttpContext RequestAborted Cancellation Token

    When the browser cancels a request, the asynchronous operation is cancelled(A task was canceled.), This can improve some performance.

    So it will not affect the application, it will only exist in the log.

    https://andrewlock.net/using-cancellationtokens-in-asp-net-core-mvc-controllers/

  • User Avatar
    0
    rickfrankel created

    Thanks @maliming I'll try look at implementing that Exception filter to filter it out of my logs as it's just filling it up with noise at the moment.

    We do lots of switching to linked accounts in my setup.

  • User Avatar
    0
    alexanderpilhar created

    @maliming thank you for this information about cancellation-tokens!

    Still, I wonder why I see an exception in my dev environment (in Visual Studio IDE, not in Logs.txt) since 8.2.1 ...

    Anyway, thank your very much for your time @maliming!

  • User Avatar
    0
    Ricavir created

    I also noticed this logs on UserFriendsCache class.

    I have the same beavior

    • while debugging the app : debug stops with the TaskCanceledException, clicking on "continue" to continu debugging the app. No side effects
    • in production : several logs but no side effects

    Here is the log :

    WARN  2020-04-19 23:40:31,807 [15   ] EN_SOFT.MyAPP.Web.Chat.SignalR.ChatHub - System.Threading.Tasks.TaskCanceledException: A task was canceled.
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, 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.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
       at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
       at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.FirstOrDefaultAsync(TPrimaryKey id)
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
       at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
       at Nito.AsyncEx.AsyncContext.<>c__DisplayClass16_0`1.&lt;Run&gt;b__0(Task`1 t)
       at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
       at System.Threading.Tasks.Task.&lt;&gt;c.&lt;.cctor&gt;b__274_0(Object obj)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location where exception was thrown ---
       at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
       at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
       at Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func)
       at MyCOMPANY.MyAPP.Friendships.Cache.UserFriendsCache.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\Cache\UserFriendsCache.cs:line 195
       at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal_callback(UserIdentifier userIdentifier)
       at Castle.Proxies.Invocations.UserFriendsCache_GetUserFriendsCacheItemInternal.InvokeMethodOnTarget()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
       at Castle.DynamicProxy.AsyncDeterminationInterceptor.Intercept(IInvocation invocation)
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier)
       at MyCOMPANY.MyAPP.Friendships.Cache.UserFriendsCache.<>c__DisplayClass8_0.<GetCacheItem>b__0(String f) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\Cache\UserFriendsCache.cs:line 46
       at Abp.Runtime.Caching.CacheExtensions.<>c__DisplayClass5_0`2.&lt;Get&gt;b__0(String k)
       at Abp.Runtime.Caching.AbpCacheBase`2.Get(TKey key, Func`2 factory)
       at Abp.Runtime.Caching.CacheExtensions.Get[TKey,TValue](ICache cache, TKey key, Func`2 factory)
       at MyCOMPANY.MyAPP.Friendships.Cache.UserFriendsCache.GetCacheItem(UserIdentifier userIdentifier) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\Cache\UserFriendsCache.cs:line 44
       at Castle.Proxies.UserFriendsCacheProxy.GetCacheItem_callback(UserIdentifier userIdentifier)
       at Castle.Proxies.Invocations.UserFriendsCache_GetCacheItem.InvokeMethodOnTarget()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
       at Castle.DynamicProxy.AsyncDeterminationInterceptor.Intercept(IInvocation invocation)
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.Proxies.UserFriendsCacheProxy.GetCacheItem(UserIdentifier userIdentifier)
       at MyCOMPANY.MyAPP.Friendships.ChatUserStateWatcher.NotifyUserConnectionStateChange(UserIdentifier user, Boolean isConnected) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\ChatUserStateWatcher.cs:line 45
       at MyCOMPANY.MyAPP.Friendships.ChatUserStateWatcher.OnlineClientManager_UserDisconnected(Object sender, OnlineUserEventArgs e) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\ChatUserStateWatcher.cs:line 41
       at Abp.RealTime.OnlineClientManager.Remove(String connectionId)
       at Abp.AspNetCore.SignalR.Hubs.OnlineClientHubBase.OnDisconnectedAsync(Exception exception)
    System.Threading.Tasks.TaskCanceledException: A task was canceled.
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, 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.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
       at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
       at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.FirstOrDefaultAsync(TPrimaryKey id)
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
       at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
       at Nito.AsyncEx.AsyncContext.<>c__DisplayClass16_0`1.&lt;Run&gt;b__0(Task`1 t)
       at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
       at System.Threading.Tasks.Task.&lt;&gt;c.&lt;.cctor&gt;b__274_0(Object obj)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location where exception was thrown ---
       at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
       at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
       at Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func)
       at MyCOMPANY.MyAPP.Friendships.Cache.UserFriendsCache.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\Cache\UserFriendsCache.cs:line 195
       at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal_callback(UserIdentifier userIdentifier)
       at Castle.Proxies.Invocations.UserFriendsCache_GetUserFriendsCacheItemInternal.InvokeMethodOnTarget()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
       at Castle.DynamicProxy.AsyncDeterminationInterceptor.Intercept(IInvocation invocation)
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.Proxies.UserFriendsCacheProxy.GetUserFriendsCacheItemInternal(UserIdentifier userIdentifier)
       at MyCOMPANY.MyAPP.Friendships.Cache.UserFriendsCache.<>c__DisplayClass8_0.<GetCacheItem>b__0(String f) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\Cache\UserFriendsCache.cs:line 46
       at Abp.Runtime.Caching.CacheExtensions.<>c__DisplayClass5_0`2.&lt;Get&gt;b__0(String k)
       at Abp.Runtime.Caching.AbpCacheBase`2.Get(TKey key, Func`2 factory)
       at Abp.Runtime.Caching.CacheExtensions.Get[TKey,TValue](ICache cache, TKey key, Func`2 factory)
       at MyCOMPANY.MyAPP.Friendships.Cache.UserFriendsCache.GetCacheItem(UserIdentifier userIdentifier) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\Cache\UserFriendsCache.cs:line 44
       at Castle.Proxies.UserFriendsCacheProxy.GetCacheItem_callback(UserIdentifier userIdentifier)
       at Castle.Proxies.Invocations.UserFriendsCache_GetCacheItem.InvokeMethodOnTarget()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Abp.Domain.Uow.UnitOfWorkInterceptor.InterceptSynchronous(IInvocation invocation)
       at Castle.DynamicProxy.AsyncDeterminationInterceptor.Intercept(IInvocation invocation)
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.Proxies.UserFriendsCacheProxy.GetCacheItem(UserIdentifier userIdentifier)
       at MyCOMPANY.MyAPP.Friendships.ChatUserStateWatcher.NotifyUserConnectionStateChange(UserIdentifier user, Boolean isConnected) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\ChatUserStateWatcher.cs:line 45
       at MyCOMPANY.MyAPP.Friendships.ChatUserStateWatcher.OnlineClientManager_UserDisconnected(Object sender, OnlineUserEventArgs e) in D:\a\1\s\aspnet-core\src\MyCOMPANY.MyAPP.Core\Friendships\ChatUserStateWatcher.cs:line 41
       at Abp.RealTime.OnlineClientManager.Remove(String connectionId)
       at Abp.AspNetCore.SignalR.Hubs.OnlineClientHubBase.OnDisconnectedAsync(Exception exception)
    
  • User Avatar
    0
    alexanderpilhar created

    I implemented the #if DEBUG preprocessor directive as a work-around for my debug environment:

    ...\CompanyName.ProjectName.Web.Core\Authentication\JwtBearer\PoinowJwtSecurityTokenHandler.cs

    #if DEBUG
                try
                {
                    AsyncHelper.RunSync(() => ValidateSecurityStampAsync(principal));
                }
                catch
                {
                    // ignore
                }
    #else
                AsyncHelper.RunSync(() => ValidateSecurityStampAsync(principal));
    #endif
    

    and

    ...\CompanyName.ProjectName.Core\Friendships\Cache\UserFriendsCache.cs

                    var user = new User();
    #if DEBUG
                    try
                    {
                        user = AsyncHelper.RunSync(() => _userManager.FindByIdAsync(userIdentifier.UserId.ToString()));
                    }
                    catch
                    {
                        // ignore
                    }
    #else
                    user = AsyncHelper.RunSync(() => _userManager.FindByIdAsync(userIdentifier.UserId.ToString()));
    #endif
    

    I would prefere a better solution, though ...

  • User Avatar
    0
    alexanderpilhar created

    I just tried with a clean install of my project (version 9.0.1) and this problem still exists.

  • User Avatar
    1
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    It might be related to cookies/cache of your browser. There might be some old tokens there. Can you see such logs on your production evironment ?

  • User Avatar
    0
    alexanderpilhar created

    Hi @ismcagdas!

    I think you are right! I cleaned my main browsers data and also tried with other browsers and the problem does not occur anymore.

    Thank you so much!