Skip to content

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

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