I'm experiencing random errors (several per day) in my mvc+ef+unity application under higher load (10+ request per sec):
I use this implementation of PerRequestLifetimeManager and tried Unity.Mvc3 too without any difference.
There are some hints that DbContext is not being disposed correctly. I am not sure if per-request is the cause of problems, because it seems to be common practise.
After further investigation I found out that request processing thread sometimes steals DbContext from other thread, so Rashid's implementation of PerRequestLifetimeManager may not be thread safe. I moved to Unity.Mvc3 again and the errors disappeared, I must have made some mistake when I tried that last time.
The only error not related were deadlocks. They were caused by collision of
SELECT ... FROM X JOIN Y ... JOIN Z ...
and
BEGIN TRAN
UPDATE Z ...
UPDATE Y ...
COMMIT TRAN
SELECT locked Y and wanted Z, TRAN locked Z and wanted Y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With