Repository navigation
Fix HybridCache reservation over-release on DisableUnderlyingData miss - #7879
Merged
Merged
Conversation
When a stampede had DisableUnderlyingData set and the value was not found in L2, every joined caller was completed with one shared ImmutableCacheItem that held a single reservation. Each caller releases one reservation when it unwraps the result, so every caller beyond the first over-released the shared item (a Debug.Assert in debug builds, a drifting counter in release builds). The miss now completes with the stampede's own cache item, which already holds one reservation per joined caller, so the counts balance. The unused GetReservedShared helper is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1646953&view=codecoverage-tab |
svick
approved these changes
Oct 29, 2026
svick
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR. This looks good to me.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1654573&view=codecoverage-tab |
mrek-msft
approved these changes
Nov 2, 2026
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.
Split out of #7876, as suggested there; this fix doesn't depend on the
GetAsyncAPI.Problem
When
GetOrCreateAsyncruns withHybridCacheEntryFlags.DisableUnderlyingDataand the value is not in L2,StampedeState<TState, T>.SetDefaultResultcompleted the shared result withImmutableCacheItem<T>.GetReservedShared(): one item holding a single reservation. Every caller joined to that stampede then callsGetReservedValue, which releases one reservation each. With N joined callers, the item is released N times against 1 reservation:Debug.Assert(newCount >= 0, "over-release detected")inCacheItem.Release.Fix
SetDefaultResultnow completes with the stampede's ownCacheItem, which already holds one reservation per joined caller (added byTryAddCaller). The default value is assigned throughSetValue/SetFallbackValue, depending on whether the item is immutable or mutable. The item is still not written to L1 or L2.GetReservedSharedis no longer used and is removed.Tests
StampedeTests.JoinedCallersWithoutUnderlyingDataBalanceReservations_{Immutable,Mutable}join 1 or 10 callers to aDisableUnderlyingDatastampede, run it, and check that:All four cases fail on
mainand pass with this change. The fullMicrosoft.Extensions.Caching.Hybrid.Testssuite passes on net8.0, net9.0, and net10.0.🤖 Generated with Claude Code
Microsoft Reviewers: Open in CodeFlow