Conversation
…tion. Added additional check to ensure we don't release a lock that's already released.
1 task
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR removes the fast-fail recursive lock check on the NuCache write semaphore and refines the release logic to avoid lock acquisition exceptions under near-simultaneous publish requests. It also fixes a typo in the exception message.
- Corrected typo in
EnsureLockedexception text. - Removed the recursive-lock guard in
Lock(...). - Updated
Release(...)to conditionally release or log a warning when the semaphore count is unexpected.
Comments suppressed due to low confidence (2)
src/Umbraco.PublishedCache.NuCache/ContentStore.cs:409
- Add unit or integration tests for concurrent lock release scenarios, especially cases where
CurrentCountis non-zero, to verify that the semaphore is released correctly and no deadlocks occur.
private void Release(WriteLockInfo lockInfo, bool commit = true)
src/Umbraco.PublishedCache.NuCache/ContentStore.cs:418
- [nitpick] Consider enhancing this warning to include more context (e.g., operation name or
lockInfodetails) so that it's easier to trace why an unexpected count occurred in production logs.
"On releasing the content store lock the current count was found unexpectedly to be non-zero with a value of {CurrentCount}."
ronaldbarendse
approved these changes
May 27, 2025
Migaroez
approved these changes
May 28, 2025
This was referenced Dec 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Resolves: #19338
Description
The linked issue reports a regression after #17246, which was introduced to avoid locking exceptions in asynchronous code.
It seems that after this, near-simultaneous requests to save and publish content results in one or more of the requests failing due to NuCache being unable to acquire a lock (the
SemaphoneSlimthat's it's based on not being released from the previous operation). You would then find the content created and published, but the failed ones wouldn't be in the cache, which is manifested in the backoffice by the message of "published but not in the cache" shown where the URLs are displayed on the "Info" panel.To resolve I've removed the "fast-fail" check we had before waiting for the
SemaphoneSlim, and allowed the wait to pick up the lock when released from the previous operation.Some advice from @ronaldbarendse:
Testing
The original issue can be replicated as shown in the linked issue from the browser console when logged into the backoffice.
You should find with this PR in place multiple requests to create, save and publish content will succeed.