JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
572 stars 119 forks source link

Adding unit test for scoped instances being shared across threads #178

Closed matthawley closed 5 years ago

matthawley commented 5 years ago

Failing unit tests for bug #173

jeremydmiller commented 5 years ago

@matthawley I'm looking at this today finally

jsheetzati commented 5 years ago

Could this explain why I am having issues with DbContext in asp.net core 3? See frequent exceptions like A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. For more information on how to avoid threading issues with DbContext or Invalid operation. The connection is closed.

Coming from asp.net core 2.2 with StructureMap where we do not have this issue. I searched for usual culprits in our code like async voids but not coming up with anything. Could very well be something else but this PR stuck out to me as a possible explanation.

matthawley commented 5 years ago

@jsheetzati If you look at the related bug, it was closed it as non reproducible. We ultimately removed Lamar and our issues went away. I can't say for sure that it's the same, but if you're attempting to get a scoped object from a transient object, it's quite possible - as that was our scenario.

jeremydmiller commented 5 years ago

@jsheetzati I tried the repro steps again today from this PR and I cannot reproduce the issue. Wanna try a different PR with reproduction steps using EF? The other time we had a bug something like this it did turn out to be something in the Expression model, but I would want to see reproduction steps that actually trip off a failure before I try changing anything