Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "ashishani"

Hi @ismcagdas, yes I do. like the example below:

public async Task DeleteAdjustmentMap(EntityDto<int> input)
{
    var allAdjustmentMaps = _adjustmentMapRepository.GetAll();
    
    ... some code...
    
    await _adjustmentMapRepository.DeleteAsync(adjustmentMap);
}

Your question reminded me of an issue that I fixed recently. It could be the cause but let me confirm with you first.

The bug was that I have an async method to delete records and and I used to call it without the key-word await. of course the DBContext was not happy sometimes, and I had an exception (sometimes) at that scope because I am using the same DBContext in 2 threads. I just rememberd that I only deployed that fix in production few days ago. I didn't see the error yet because I restart IIS everyday.

The code before fixing the bug looked like this:

var opportunityLineItemIdsToDelete = (from l in allOpportunityLineItems
                                                              where l.OpportunityId == opportunityOutput.Id
                                                              && !opportunityLineItemReferences.Contains(l.LineItemReference)
                                                              select l.Id).ToList();

if (opportunityLineItemIdsToDelete.Count() > 0)
{
    **_ = DeleteOpportunityLineItemsRelatedEntities(opportunityLineItemIdsToDelete, true);**
}

after fixing the bug, the code looked like this:

var opportunityLineItemIdsToDelete = (from l in allOpportunityLineItems
                                                              where l.OpportunityId == opportunityOutput.Id
                                                              && !opportunityLineItemReferences.Contains(l.LineItemReference)
                                                              select l.Id).ToList();

if (opportunityLineItemIdsToDelete.Count() > 0)
{
    **await DeleteOpportunityLineItemsRelatedEntities(opportunityLineItemIdsToDelete, true);**
}

Would that lead to the leak issue? I stopped restarting the server so I can see the error if it happens.

Sorry, most probably the issue I was having is not relevant to the Lifetime validation failed.

Thanks

Hi @ismcagdas, Yes it is still happening and it is hard to spot the location of the database connection leak. My app reaches the limit of SQL connections (100 open connections) every couple of days. At the moment I do restart IIS almost everyday to kill the open DB connections until I identify the scope of problem. I did a code review and added a UnitOfWork using statement and made sure that I complete the UnitOfWork in the end, like this:

        using (var unitOfWork = _unitOfWorkManager.Begin())
        {
            ... some code
            
            await unitOfWork.CompleteAsync();
        }
        

I do have 2 DBContexts each one accessing a different database to migrate list of customers, products and other type of data every day. Not sure if it can be relavent.

Other scope that I am suspecting to be the cause is an exception when validating tokens. There is a Salesforce App that consumes my .Net Core 3 API. I am also using Angular 8. I noticed that there are lots of Token validation throwing an exception because the token used is expired. I am just suspecing that this may be a scope which has a unit of work and the exception doesn't allow the unit of work to complete (Maybe?)

I am trying to think of an approach to identify the source. I am open for suggestions.

Thanks, Ali

Hi, I am having the same issue. I am a recent client who uses v8.0.0

However, the reason I am currently investigating this issue is that I suspect it is causing some data leak which causes my app to reach the maximum number of connections in the pool "100 connections". This forces me to restart the application in IIS.

The reason for me to think that the error in this Question is the cause, I am suspecting that there is a unit of work within that scope and it doesn't execute "uow.Complete();" to close the DB Connection.

I am not sure it is the cause, but this is the error I get and it always happen the same time when the token get expired.


System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at Microsoft.Data.SqlClient.SqlConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction(IsolationLevel isolationLevel) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.BeginTransaction(DatabaseFacade databaseFacade, IsolationLevel isolationLevel) at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.CreateDbContext[TDbContext](String connectionString, IDbContextResolver dbContextResolver) at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.GetOrCreateDbContext[TDbContext](Nullable1 multiTenancySide, String name) at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase3.get_Table() at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase3.Insert(TEntity entity) at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.InsertAsync(TEntity enti...


This is how my log looks like:

Showing 1 to 3 of 3 entries