-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MemoryCache - Remove unhandled exception handler #105853
MemoryCache - Remove unhandled exception handler #105853
Conversation
@@ -39,8 +39,6 @@ public class MemoryCache : ObjectCache, IEnumerable, IDisposable | |||
private bool _useMemoryCacheManager = true; | |||
private bool _throwOnDisposed; | |||
private EventHandler _onAppDomainUnload; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the AppDomainUnload event handler be deleted for the same reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppDomainUnload doesn't run the same danger of being called unexpectedly on a stack that might be holding locks or be in some other inconsistent state. So I don't think it's a danger here. Since System.Runtime.Caching is simply a bridge package to allow folks to migrate from NetFx to .Net, I tend to approach with a servicing mentality and only make the changes that are necessary. (Also, the 1st party customer affected by this is still targeting 6.0 with some of their services, so this actually is servicing as we will want to backport whatever we do here.)
I can add another commit if you guys disagree with the conservative approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have constant trickle of shutdown bugs (hangs or crashes) caused by unnecessary code running during shutdown. I think it is just a matter of time until somebody hits a problem with the AppDomainUnload handler.
this actually is servicing as we will want to backport whatever we do here.
It is fine to do a minimal backport that just fixes the customer issue for servicing and do more complete fix in main. It is often how the fixes for the shutdown bugs look like. For example:
- Remove preventing EH and entering EE at shutdown #100293 - full fix in main
- [Release/8.0] Remove preventing EH at shutdown #100836 - partial backport for servicing
Re-fixes #64115 in a different way from the previous fix.
The locks causing deadlock here are not known to MemoryCache at all. They exist in Timer and ThreadPool components. But the unhandled exception handler in MemoryCache doesn't do anything other than dispose the stats timer in .Net Core. (In NetFx, the deadlock risk wasn't the same, and the unhandled exception handler also had to clean up perf counters that could live beyond the process lifetime.) So this exception handler isn't really needed anymore.