Skip to content
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

Cleanup internal ComWrappers cache when object enters Finalization queue #52771

Merged
merged 9 commits into from
May 25, 2021

Conversation

AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented May 14, 2021

The ComWrappers API has a deficiency/race during native object wrapper (RCW) cleanup. This is rare but has been observed in tight loops with complex object types. The scenario occurs when native object A is freed, its memory is reused for native object B, and that memory is provided back to the runtime but the previous mapping remains to the wrapper for native object A. The issue occurs based on an incorrect expectation between when the RCW's Finalizer will run and when the mapping between native IUnknown* to RCW will be removed from the internal cache.

The solution is to remove the mapping when the RCW itself is scheduled for Finalization.

The issue was reported at microsoft/CsWinRT#762.

Additional issues
Fixes #53160

@AaronRobinsonMSFT
Copy link
Member Author

/cc @elinor-fung @jkoritzinsky

@AaronRobinsonMSFT
Copy link
Member Author

Failure is #52710

src/coreclr/vm/interoplibinterface.h Outdated Show resolved Hide resolved
src/coreclr/vm/interoplibinterface.cpp Show resolved Hide resolved
src/coreclr/vm/interoplibinterface.h Outdated Show resolved Hide resolved
is an option remove the use of Detach in the IsActive logic and
narrow its use to the cache cleanup scenario only.
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 4bdaa8e into dotnet:main May 25, 2021
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the cleanup_cache branch May 25, 2021 15:15
@ghost ghost locked as resolved and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants