question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A second operation starte d on this context before a previous operation completed

See original GitHub issue
  • Abp package version 4.5.0.
  • .Net Core2.2. I use a timer at the reference layer to collect some serial port data and then use the event bus to process the data.Now I find that the program runs for a while and occasionally has a problem:

Unhandled Exception: System.InvalidOperationException: A second operation starte d on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance memb ers are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoid ing nested invocations. at Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSe ction() at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveCha nges(IReadOnlyList1 entriesToSave) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveCha nges(Boolean acceptAllChangesOnSuccess) at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChang esOnSuccess) at Abp.EntityFrameworkCore.AbpDbContext.SaveChanges() at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext3.SaveChanges() at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.SaveChangesInDbContext(DbCont ext dbContext) at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.SaveChanges() at Abp.EntityFrameworkCore.AbpDbContext.SaveChanges() at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext`3.SaveChanges() at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.SaveChangesInDbContext(DbCont ext dbContext) at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.SaveChanges() at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CompleteUow() at Abp.Domain.Uow.UnitOfWorkBase.Complete() at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation , UnitOfWorkOptions options) at Castle.DynamicProxy.AbstractInvocation.Proceed() at SensorBroker.Schedules.CompositeSensor.CompositeSensorCommunicatorHandler. OnParseData(Object state) in D:\SVN\VR-Code\Trunk\SensorBroker\Source\sensorbrok er-aspnet-core\src\SensorBroker.Application\Schedules\CompositeSensor\CompositeS ensorCommunicatorHandler.cs:line 144

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
guaicaiboshicommented, Dec 10, 2019

@guaicaiboshi Can you provide complete code to reproduce the problem? I’ll do a demo sometime

1reaction
ryancyqcommented, Dec 5, 2019

You can try using AsyncHelper.RunSync() instead of Wait()

AsyncHelper.RunSync(() => 
pressureSensorDataManager.AddOrUpdateSensorData(result) );
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework Core: A second operation started on this ...
(A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same ...
Read more >
[BUG] A second operation started on this context before ...
I am using ef core 3.1.5 and asp.net core 3.1 and am having this constant issue around a function that sets a view...
Read more >
DbContext Lifetime, Configuration, and Initialization
A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same ...
Read more >
DBContext- A second operation started on this context ...
A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance...
Read more >
A second operation started in this context before a ... - YouTube
A second operation started in this context before a previous asynchronous operation completed. 3.8K views · 4 years ago ...more ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found