dotnet / dotnet/wpf

System.Xaml.SafeSecurityHelper.CleanupCollectedAssemblies OOM will break the application process

Open
#8,857 3 comments 0 reactions 0 assignees View on GitHub
Investigate
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.