[release/6.0-staging] Fix AV in host from tracing on exit #101260
Merged
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.
Backport of #77425 and #77765 to release/6.0-staging
/cc @elinor-fung
Customer Impact
This is affecting MATLAB, their customers, and their users. A common scenario for their customers is publishing MATLAB functions as .NET assemblies that can be used in .NET applications. This workflow runs into the AV addressed by this fix. This crash prevents those customers and their users from upgrading to the latest version of MATLAB - this bug effectively introduces a breaking change in their latest version.
The issue was that we were using a static variable that had a destructor for locking around tracing. If a thread calls exit, the static destructor is called on that thread with no synchronization with other threads. Other threads would try to use the destructed object, resulting in a crash.
The fix switches to a mechanism that does not have a destructor and removes unnecessary usage of the lock.
Regression
Testing
The original fixes in .NET 8 were verified by the customer. This customer has verified that .NET 8 works while .NET 6 does not.
Risk
Low. This fix has been in since early .NET 8.