Threading issues with DbContext
See original GitHub issueI am having threading issues with DbContext + Lamar. Seeing a few errors, but this one is the most common A second operation started on this context before a previous operation completed
. If I switch over to Microsoft DI, I do not have the same issue.
I created a reproducible sample here: https://github.com/jsheetzati/lamarExample. Currently, the project is setup to use Lamar DI, but I also have comments to switch the project over to Microsoft DI.
In order to run the project, please add a DB connection string to Context
and SecondContext
. I attempted to recreate the problem using the InMemoryProvider but was not having luck with that provider. If you use SQL Server, create a sample table in the database with the following definition:
create table Book
(
Id int identity(1,1),
Title nvarchar(30),
Author nvarchar(30)
)
I used artillery to hit the API method with a bunch of requests simultaneously.
npm install -g artillery
artillery quick -n 5 --count 10 http://localhost:5000/Book/InsertAndReturn
Please let me know if you need any further information to reproduce the issue. Fairly confident at this point that Lamar is introducing a similar bug in one of our applications. There very well could be something wrong with our Lamar configuration as well, but I am not sure what that exactly is.
Thanks for all the hard work making this project. Looking forward to make the switch from StructureMap to Lamar ๐
Edit: I am not sure if this is related to https://github.com/JasperFx/lamar/issues/173, but that is what initially prompted me to dig into our issue to see if it was something similar.
Package Information ASP.NET Core 3.0 Lamar 3.2.0 Lamar.Microsoft.DependencyInjection 4.0.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:13 (7 by maintainers)
FINALLY, thereโs some optimism on this one. Maybe, maybe the fix for #215 knocks this one out as well, but weโll see.
@rofr I did try enabling MARS which fixed some problems with read operations. I was still having some odd behavior when doing writes.
I am pretty sure this is the same issue since the ISession hash code was the same between two threads.
Switching back to StructureMap made the problem disappear completely, even with MARS disabled.