-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ContentStore locking exceptions in async code #17246
Conversation
As expected, the test without fix results in this exception:
I've applied the same change in The only remaining usage of Umbraco-CMS/src/Umbraco.Web.Common/Cache/HttpContextRequestAppCache.cs Lines 215 to 263 in 7787af2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me
* Add ContentCache test * Use SemaphoreSlim as write lock * Apply lock imrpovements to SnapDictionary * Obsolete unused MonitorLock (cherry picked from commit c3db345)
Awesome, let's verify whether this not only fixes the test, but also the runtime exceptions!👍🏻 Looking more into |
* Add ContentCache test * Use SemaphoreSlim as write lock * Apply lock imrpovements to SnapDictionary * Obsolete unused MonitorLock (cherry picked from commit c3db345)
Looking at the stack trace, the error happens in a notification handler (as notifications are published in the |
Prerequisites
Description
After large Deploy operations (like an environment restore) has completed and the CMS tries to update the content cache (NuCache) as part of completing the Umbraco scope, the following exceptions were thrown:
This all originates from the
ContentStore
either not 'seeing' it already has a write lock or getting a timeout when trying to get it (essentially deadlocking). Looking at the locking implementation in this class, it usesMonitor
, which has the following requirement:But looking at the code and stack trace, the lock/monitor is entered and exited in different methods and they can potentially be called from different threads, which is especially likely if it contains async calls in-between them (Deploy heavily uses async and does more work in a single lock, further increasing the chances of exiting on a different thread).
I've added a test showcasing one of the exceptions and will push a fix that uses
SemaphoreSlim
.