Skip to content

Commit

Permalink
[release/8.0-staging] Sys.RT.Caching.MemoryCache - Remove unhandled e…
Browse files Browse the repository at this point in the history
…xception handler (#106221)

* Remove UnhandledException handler from MemoryCache to avoid deadlock.

* Update Sys.RT.Caching csproj for servicing build.
  • Loading branch information
StephenMolloy authored Aug 22, 2024
1 parent 78b77de commit 900c83f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ServicingVersion>1</ServicingVersion>
<AddNETFrameworkPlaceholderFileToPackage>true</AddNETFrameworkPlaceholderFileToPackage>
<AddXamarinPlaceholderFilesToPackage>true</AddXamarinPlaceholderFilesToPackage>
<AddNETFrameworkAssemblyReferenceToPackage>true</AddNETFrameworkAssemblyReferenceToPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class MemoryCache : ObjectCache, IEnumerable, IDisposable
private bool _useMemoryCacheManager = true;
private bool _throwOnDisposed;
private EventHandler _onAppDomainUnload;
private UnhandledExceptionEventHandler _onUnhandledException;
#if NETCOREAPP
[UnsupportedOSPlatformGuard("browser")]
private static bool _countersSupported => !OperatingSystem.IsBrowser();
Expand Down Expand Up @@ -219,9 +218,6 @@ private void InitDisposableMembers(NameValueCollection config)
EventHandler onAppDomainUnload = new EventHandler(OnAppDomainUnload);
appDomain.DomainUnload += onAppDomainUnload;
_onAppDomainUnload = onAppDomainUnload;
UnhandledExceptionEventHandler onUnhandledException = new UnhandledExceptionEventHandler(OnUnhandledException);
appDomain.UnhandledException += onUnhandledException;
_onUnhandledException = onUnhandledException;
dispose = false;
}
finally
Expand All @@ -238,16 +234,6 @@ private void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs)
Dispose();
}

private void OnUnhandledException(object sender, UnhandledExceptionEventArgs eventArgs)
{
// if the CLR is terminating, dispose the cache.
// This will dispose the perf counters
if (eventArgs.IsTerminating)
{
Dispose();
}
}

private static void ValidatePolicy(CacheItemPolicy policy)
{
if (policy.AbsoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration
Expand Down Expand Up @@ -500,10 +486,6 @@ private void DisposeSafeCritical()
{
appDomain.DomainUnload -= _onAppDomainUnload;
}
if (_onUnhandledException != null)
{
appDomain.UnhandledException -= _onUnhandledException;
}
}

private object GetInternal(string key, string regionName)
Expand Down

0 comments on commit 900c83f

Please sign in to comment.