Bug 34398 - runtime hook for unhandled exceptions not always called
Summary: runtime hook for unhandled exceptions not always called
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Blocks: 34385
  Show dependency tree
Reported: 2015-09-29 10:48 UTC by Rodrigo Kumpera
Modified: 2015-09-29 11:07 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 34398 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Rodrigo Kumpera 2015-09-29 10:48:39 UTC
We don't call mono_invoke_unhandled_exception_hook for all unhandled exception.

This is making the iOS team job harder when debugging issues related to it.

We should fix this puppy and add tests for that entrypoint.

Apparently unhandled exceptions in finalizers are ignored if there's an AppDomain.UnhandledException handler.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-09-29 11:07:42 UTC
Just to save what I found out:

There's mono_unhandled_exception [1], which doesn't always exit [2] nor call the hook.

mono_unhandled_exception is called by:
1) ves_icall_System_Runtime_Remoting_Messaging_AsyncResult_Invoke [3], but that function doesn't check if the process should exit (nor does it call the hook)

2)  mono_thread_internal_unhandled_exception [4], which exits (but doesn't call the hook) if Environment.ExitCode is 1 (which the user can change if they wish).

3) mono_handle_exception_internal [5], which also doesn't call neither the hook nor does it ever exit.

[1] https://github.com/mono/mono/blob/d1a87bcac2a8a6fdb669b9789ca608cc89cd9eaa/mono/metadata/object.c#L4091
[2] It's setting Environment.ExitCode to signal that the process should terminate, but the user can also set this in any event handler.
[3] https://github.com/mono/mono/blob/d1a87bcac2a8a6fdb669b9789ca608cc89cd9eaa/mono/metadata/object.c#L6117
[4] https://github.com/mono/mono/blob/d1a87bcac2a8a6fdb669b9789ca608cc89cd9eaa/mono/metadata/threads.c#L4701