Skip to content
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

Fatal error instead of calling Unhandled Exception Filter #95330

Closed
awbushnell opened this issue Nov 28, 2023 · 9 comments
Closed

Fatal error instead of calling Unhandled Exception Filter #95330

awbushnell opened this issue Nov 28, 2023 · 9 comments

Comments

@awbushnell
Copy link

Description

We have an X64 Windows native application that also mixes in .netcore code. As part of our application we make use of unhandled Exception filters to collect runtime crash data from production uses of the product. We recently have moved from .netFramework 4.8 to .netCore version 7 and working on 8. We have found an issue where under certain circumstances, when an access violation occurs in the code, our handler no longer gets called… It appears that if the the access violation makes it way into some managed unwind logic, things end up stuck there and eventually, the app just aborts… never calling any unhandled exception filters. This seems somewhat specific to access violation. I have tried “RaiseException” with other values and things seem ok. In addition, if normal std::exceptions seem fine as well.

ConsoleTestApplication.zip

Reproduction Steps

I have attached a zip file that contains a solution with projects and code necessary to replicate what we are seeing in our much larger application. To replicate using the attached please do the following:

  • Open ConsoleTestApplication.sln in Visual Studio 2022
  • Build the solution.
  • Run the resulting consoletestapplication.exe.

Expected behavior

when running the resulting executable, you should see the following Message Box appear:

Bec6f0aa2a2654d79992db3b28b9ab133638355060847537255_CERMsg

Actual behavior

Instead, what happens is this output in the console

Testing unhandled exceptions in netcore!
Generationg System Access violation by Win32 RaiseException API.
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:

at . CLRInterop.makeException()

at .? A0xd840671c.managedTestFunc()

ConsoleTestApplication.exe (process 9288) exited with code -1073741819.

Regression?

This worked as of .netframrework 4.8

Known Workarounds

No response

Configuration

.net7 and .net8 on Windows x64

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 28, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 28, 2023
@vcsjones vcsjones added area-ExceptionHandling-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 28, 2023
@jkotas
Copy link
Member

jkotas commented Nov 28, 2023

Access violations are symptoms of corrupted process state, and they are not catchable in .NET Core/5+.

Why do you need to catch access violations?

@awbushnell
Copy link
Author

Access violations are symptoms of corrupted process state, and they are not catchable in .NET Core/5+.

Why do you need to catch access violations?

@jkotas In this case we are not attempting to catch but rather we have a native unhandled exception filter that is setup so we can do some data collection etc. then shutdown. The issue in this particular case is that the code flow goes something like :

Native -> managed -> native and in the lower native layer is where structured exception occurs... and once it winds back to managed all is lost and our filter does not get called..

@jkotas
Copy link
Member

jkotas commented Nov 30, 2023

#79706 (comment) is a discussion about exposing a new API to allows installing a custom (unmanaged) handler for fatal errors like access violations that are symptoms of unrecoverable process state corruption.

Would that work for you?

@awbushnell
Copy link
Author

#79706 (comment) is a discussion about exposing a new API to allows installing a custom (unmanaged) handler for fatal errors like access violations that are symptoms of unrecoverable process state corruption.

Would that work for you?

@jkotas If I understand that properly, it essentially is a call back mechanism to get control before the fatal termination? If I follow that properly, then yes, that seems it would help us in this case.

@jkotas
Copy link
Member

jkotas commented Dec 1, 2023

Yes, that's correct. Do you have an opinion about what the signature of the callback should be?

@awbushnell
Copy link
Author

Yes, that's correct. Do you have an opinion about what the signature of the callback should be?

@jkotas Off top of my head, if the callback we registered were similar to what one registers for the Win32 Unhandled Exception filter, that would probably work best for us. But haven't given too much thought overall.

@cwensley
Copy link

cwensley commented Apr 15, 2024

We have a Mac and Windows desktop C/C++ application and would like have this implemented too so we can continue to use our custom crash reporting logic. On Mac we are able to override the signal handlers to do this, but there's no such facility on Windows.

Ideally this would be called from EEPolicy::HandleFatalError or equivalent so we can at least get the PEXCEPTION_POINTERS parameter to report all of the same relevant information.

We are investigating the use of AddVectoredExceptionHandler to catch these cases, which appears to work for stack overflows and access denied, but not uncaught exceptions .NET threads.

@jkotas
Copy link
Member

jkotas commented Apr 15, 2024

cc @VSadov

@jkotas
Copy link
Member

jkotas commented Apr 25, 2024

Superseded by #101560

@jkotas jkotas closed this as completed Apr 25, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants