System.Xaml.SafeSecurityHelper.CleanupCollectedAssemblies OOM will break the application process
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
The System.Xaml.SafeSecurityHelper.CleanupCollectedAssemblies method will collect the assembly in GCNotificationToken. However, memory needs to be allocated during the cleanup task which may throw System.OutOfMemoryException. As we know from the features of dotnet, any uncaught exception thrown in the background thread will cause the process to crash.
### Reproduction Steps
When the memory is insufficient, raise System.Xaml.SafeSecurityHelper.CleanupCollectedAssemblies method.
### Expected behavior
The cleanup task fail when the memory is insufficient, but not cause the application process to crash.
### Actual behavior
The application process crash with the stacktrace:
```
System.OutOfMemoryException
at System.Xaml.SafeSecurityHelper.CleanupCollectedAssemblies(Object state)
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback();
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Impact
_No response_
### Configuration
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.