Base solution for your next web application
Open Closed

UOW Transaction Timeout #1237


User avatar
0
tjackadams created

Hello,

I seemed to have developed a bit of an issue since updating to abp v0.9.1.1 from 0.8.4.1.

Currently i have this background worker and it throws the following exception

System.Transactions.TransactionAbortedException occurred HResult=-2146233087 Message=The transaction has aborted. Source=System.Transactions StackTrace: at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState) at System.Transactions.CommittableTransaction.Commit() at System.Transactions.TransactionScope.InternalDispose() at System.Transactions.TransactionScope.Dispose() at Abp.EntityFramework.Uow.EfUnitOfWork.DisposeUow() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 191 at Abp.EntityFramework.Uow.EfUnitOfWork.CompleteUow() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 89 at Abp.Domain.Uow.UnitOfWorkBase.Complete() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:line 239 at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 54 at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 47 at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 35 at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.EfRepositoryBase`3Proxy_18.GetAllList() at Portal.AutoTask.DownloadAutoTaskContactsFull.DoWork() in C:\Users\admin.tom.adams.CTL-PORTAL\Documents\Visual Studio 2015\Projects\Portal\Portal.Application\AutoTask\BackgroundWorkers.cs:line 208 InnerException: HResult=-2146233083 Message=Transaction Timeout InnerException:

Here is the actual background job. As you can see its very simple (just testing at the moment).

public class DownloadAutoTaskContactsFull : PeriodicBackgroundWorkerBase, ISingletonDependency
    {
        private readonly IRepository<AutoTaskContact, long> _autoTaskContactRepository;
        public DownloadAutoTaskContactsFull(AbpTimer timer, IRepository<AutoTaskContact,long> autoTaskContactRepository) : base(timer)
        {
            Timer.Period = 5000;

            _autoTaskContactRepository = autoTaskContactRepository;
        }

        [UnitOfWork]
        protected override void DoWork()
        {
            var contacts = _autoTaskContactRepository.GetAllList();

            Debug.WriteLine("{0} Contacts", contacts.Count);
        }
    }

It seems to be the GetAllList command that throws the exception. Essentially it looks as if its doing nothing for ~15 minutes before throwing the exception.

I've tested with other commands such as SingleOrDefault with a filter and it works fine and returns a result. Through testing it seems to be any list > 1000 records, the table itself only has 9000 records which isn't huge.

I have also tested this with other entities and in the application service layer as well and its the same result (timeout). If i query through sql management studio, then it completes in a tiny amount of time, < 1ms.

As you can see i am using the built in IRepository, not my own. Any suggestions on how to resolve this are appreciated. Thanks


3 Answer(s)
  • User Avatar
    0
    tjackadams created

    I've done a bit more testing this morning just to try and rule a few things out.

    I've setup a brand new EF project (no abp packages installed) and it can pull a list of Contacts out fine.

    I've changed the code slightly just to see if it was pulling them all out at the same time that was the issue. Here is the new code.

    [UnitOfWork]
            protected override void DoWork()
            {
                //var contacts = _autoTaskContactRepository.GetAllList();
    
                var totalContacts = _autoTaskContactRepository.Count();
                var pages = Math.Ceiling(Convert.ToDouble(totalContacts)/500);
                var contacts = new List<AutoTaskContact>();
    
                for (int i = 0; i < pages; i++)
                {
                        contacts.AddRange(_autoTaskContactRepository.GetAll().OrderBy(c => c.AccountID).Skip(i * 500).Take(500));                             
                }
    
    
                Debug.WriteLine("{0} Contacts", contacts.Count);
            }
    

    If i loop through the iteration with breakpoints, i can see that it is working, however each loop takes longer and longer to complete. I also fire up sql profiler and i can see the actual sql command completes in no time at all, but the time between each request gets longer and longer.

    I can actually get it to run now if i change the code to this

    //[UnitOfWork]
            protected override void DoWork()
            {
                //var contacts = _autoTaskContactRepository.GetAllList();
    
                var totalContacts = _autoTaskContactRepository.Count();
                var pages = Math.Ceiling(Convert.ToDouble(totalContacts)/500);
                var contacts = new List<AutoTaskContact>();
    
                for (int i = 0; i < pages; i++)
                {
                    using (var unitOfWork = _unitOfWorkManager.Begin())
                    {
                        contacts.AddRange(_autoTaskContactRepository.GetAll().OrderBy(c => c.AccountID).Skip(i * 500).Take(500));
                        unitOfWork.Complete();
                    }
                    
                }
    
    
                Debug.WriteLine("{0} Contacts", contacts.Count);
            }
    

    but it still takes a relatively long time to complete, 1 minute 34 to bring 9207 records out of sql.

    Cheers

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Can you upgrade Abp.* packages to v0.9.3.0. This performance issue is resolved. Please try it and write us again.

    Thanks.

  • User Avatar
    0
    tjackadams created

    Resolved after upgrading to v0.9.3.0. Many Thanks