Hi Expert,
I was doing API load testing through JMeter. When I call RegisterTenant API with load of 10 threads i.e. calling of RegisterTenant 10 times in one go, I keep getting below error.
System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseSqlServer' call. ---> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 90) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__164_0(Task1 result) 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 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.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken) ClientConnectionId:feeb5bd9-541f-4497-8a32-ac9d97f1930d Error Number:1205,State:51,Class:13 --- End of inner exception stack trace --- at Microsoft.EntityFrameworkCore.Update.ReaderModificat...
I tried adding EnableRetryOnFailure() as recommnded in the above error message. See below code:
public static class iVendDbContextConfigurer { public static void Configure(DbContextOptionsBuilder<iVendDbContext> builder, string connectionString) { builder.UseSqlServer(connectionString, option => option.EnableRetryOnFailure()); }
public static void Configure(DbContextOptionsBuilder<iVendDbContext> builder, DbConnection connection)
{
builder.UseSqlServer(connection, option => option.EnableRetryOnFailure());
}
}
But when I add the above the back end does not run and throws following error in the log file:
ERROR 2021-04-07 19:16:52,943 [9 ] e.Diagnostics.ExceptionHandlerMiddleware - An unhandled exception has occurred while executing the request.
System.InvalidOperationException: The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit.
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.OnFirstExecution()
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func
3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1 source)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 source, Expression
1 predicate)
at Abp.Domain.Repositories.AbpRepositoryBase2.FirstOrDefault(TPrimaryKey id) at Castle.Proxies.Invocations.IRepository
2_FirstOrDefault.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.IRepository1Proxy.FirstOrDefault(Int32 id) at Abp.MultiTenancy.TenantCache
2.GetTenantOrNull(Int32 tenantId)
at Castle.Proxies.TenantCache2Proxy.GetTenantOrNull_callback(Int32 tenantId) at Castle.Proxies.Invocations.TenantCache
2_GetTenantOrNull.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.TenantCache2Proxy.GetTenantOrNull(Int32 tenantId) at Abp.MultiTenancy.TenantCache
2.<>c__DisplayClass7_0.<GetOrNull>b__0()
at Abp.Runtime.Caching.TypedCacheExtensions.<>c__DisplayClass0_02.<Get>b__0(TKey k) at Abp.Runtime.Caching.TypedCacheWrapper
2.<>c__DisplayClass16_0.<Get>b__0(String k)
at Abp.Runtime.Caching.AbpCacheBase2.Get(TKey key, Func
2 factory)
at Abp.Runtime.Caching.TypedCacheWrapper2.Get(TKey key, Func
2 factory)
at Abp.Runtime.Caching.TypedCacheExtensions.Get[TKey,TValue](ITypedCache2 cache, TKey key, Func
1 factory)
at Abp.MultiTenancy.TenantCache2.GetOrNull(Int32 tenantId) at Castle.Proxies.TenantCache
2Proxy.GetOrNull_callback_1(Int32 tenantId)
at Castle.Proxies.Invocations.ITenantCache_GetOrNull.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.TenantCache2Proxy.GetOrNull(Int32 tenantId) at Abp.MultiTenancy.TenantStore.Find(Int32 tenantId) at Abp.MultiTenancy.TenantResolver.GetTenantIdFromContributors() at Abp.MultiTenancy.TenantResolver.ResolveTenantId() at Abp.Runtime.Session.ClaimsAbpSession.get_TenantId() at Abp.Domain.Uow.UnitOfWorkBase.SetFilters(List
1 filterOverrides)
at Abp.Domain.Uow.UnitOfWorkBase.Begin(UnitOfWorkOptions options)
at Abp.Domain.Uow.UnitOfWorkManager.Begin(UnitOfWorkOptions options)
at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous(IInvocation invocation)
at Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.
Can you please help me here.
Regards, Mahendra