Serialize VSD DispatchCache unlinking with cache write lock#128868
Merged
Conversation
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix DispatchCache self-loop causing process hang
Serialize VSD DispatchCache unlinking with cache write lock
Jun 1, 2026
Contributor
|
Tagging subscribers to this area: @agocke |
jkotas
approved these changes
Jun 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a race in the VSD DispatchCache where collectible ALC teardown could unlink cache chain entries concurrently with Insert/PromoteChainEntry, breaking the single-writer assumption and producing self-referential chains that hang VSD resolution. The fix exposes the existing cache write lock and acquires it around the two unlink loops invoked during cache reset and manager teardown.
Changes:
- Expose
DispatchCache::GetWriteLock()(underCHAIN_LOOKUP). - Take
m_writeLockaround theIterator::UnlinkEntry()loops inVirtualCallStubManager::ResetCache()and~VirtualCallStubManager().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/vm/virtualcallstub.h | Adds DispatchCache::GetWriteLock() accessor (CHAIN_LOOKUP only) to allow external callers to serialize with cache writers. |
| src/coreclr/vm/virtualcallstub.cpp | Wraps the two DispatchCache::Iterator::UnlinkEntry() loops in ResetCache and the destructor with CrstHolder(g_resolveCache->GetWriteLock()) under CHAIN_LOOKUP. |
davidwrighton
approved these changes
Jun 1, 2026
wtgodbe
approved these changes
Jun 1, 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.
Collectible ALC teardown can unlink
g_resolveCachebucket entries concurrently withInsert/PromoteChainEntry, violating the cache’s single-writer assumption and allowing self-referential chain cycles that hang VSD resolution. This change restores writer serialization for unlink paths.DispatchCache API surface
DispatchCache::GetWriteLock()(underCHAIN_LOOKUP) to expose the existing cache writer lock for safe external mutation paths.Collectible-unload unlink serialization
DispatchCache::Iterator::UnlinkEntry()loops withCrstHolderin:VirtualCallStubManager::ResetCache()VirtualCallStubManager::~VirtualCallStubManager()CHAIN_LOOKUP, matching wherem_writeLockexists and where chain mutation races matter.Resulting invariant
Insert,PromoteChainEntry, unlink purge) are serialized by the same lock.Fixes #128859