Open Closed

API Load Test #10232


0
mahendra created

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.ContinuationResultTaskFromResultTask2.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&lt;iVendDbContext&gt; 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, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 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, Expression1 predicate) at Abp.Domain.Repositories.AbpRepositoryBase2.FirstOrDefault(TPrimaryKey id) at Castle.Proxies.Invocations.IRepository2_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.TenantCache2.GetTenantOrNull(Int32 tenantId) at Castle.Proxies.TenantCache2Proxy.GetTenantOrNull_callback(Int32 tenantId) at Castle.Proxies.Invocations.TenantCache2_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.TenantCache2.<>c__DisplayClass7_0.<GetOrNull>b__0() at Abp.Runtime.Caching.TypedCacheExtensions.<>c__DisplayClass0_02.<Get>b__0(TKey k) at Abp.Runtime.Caching.TypedCacheWrapper2.<>c__DisplayClass16_0.<Get>b__0(String k) at Abp.Runtime.Caching.AbpCacheBase2.Get(TKey key, Func2 factory) at Abp.Runtime.Caching.TypedCacheWrapper2.Get(TKey key, Func2 factory) at Abp.Runtime.Caching.TypedCacheExtensions.Get[TKey,TValue](ITypedCache2 cache, TKey key, Func1 factory) at Abp.MultiTenancy.TenantCache2.GetOrNull(Int32 tenantId) at Castle.Proxies.TenantCache2Proxy.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(List1 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


1 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi @mahendra

    Could you create an issue on GitHub about this ? We can work on this, try to reproduce and make enhancements if possible.

    Thanks,