-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix unhandled exception reporting corner cases #118450
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
Fix unhandled exception reporting corner cases #118450
Conversation
There are several issues with processing exceptions that are not handled by managed code on Windows: * Sometimes the AppDomain.UnhandledException event is sent multiple times * Exception flowing to foreign native code is reported as unhandled even when it is actually caught by the native code * In rare cases, the unhandled exception stack trace is doubled This change fixes them by not reporting the unhandled exception in the SfiNext on Windows. It just raises the underlying SEH exception there with the thread marked so that the personality routines for the managed frames won't run the managed exception handling code. If the exception is truly unhandled, the `InternalUnhandledExceptionFilter_Worker` will be called by the unhandled exception filter installed for the process and report the exception as unhandled. If that exception ends up being caught by a foreign native code, then nothing will be reported. Close dotnet#115215
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.
Pull Request Overview
This PR fixes several issues with unhandled exception reporting on Windows by changing how exceptions are processed when they propagate to native code. The main goal is to prevent duplicate unhandled exception events and incorrect reporting of exceptions that are actually caught by foreign native code.
Key changes:
- Renamed thread state flag from
TSNC_UnhandledException2ndPass
toTSNC_SkipManagedPersonalityRoutine
to better reflect its purpose - Modified exception handling logic to use
RaiseException
instead of immediately reporting unhandled exceptions inSfiNext
on Windows - Streamlined the flow so truly unhandled exceptions are reported by the process-level unhandled exception filter
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/coreclr/vm/threads.h | Renames thread state flag to better reflect its purpose of skipping managed personality routines |
src/coreclr/vm/exceptionhandling.cpp | Updates exception handling logic to defer unhandled exception reporting and use RaiseException on Windows |
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.
Thanks
The unhandled exceptions test is failing, debug build was passing for me locally, I am investigating what's wrong. |
@jkotas I have fixed the ordering of the UnhandledException event and the calls to finally that was causing the test failure in my last commit. |
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.
Thank you!
There are several issues with processing exceptions that are not handled by managed code on Windows:
This change fixes them by not reporting the unhandled exception in the
SfiNext
on Windows. It just raises the underlying SEH exception there with the thread marked so that the personality routines for the managed frames won't run the managed exception handling code. If the exception is truly unhandled, theInternalUnhandledExceptionFilter_Worker
will be called by the unhandled exception filter installed for the process and report the exception as unhandled.If that exception ends up being caught by a foreign native code, then nothing will be reported.
Close #115215