Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lambdageek
Copy link
Member

Backport of #21096 to 2020-02


Related to #21009.

There are two scenarios:

  1. When someone force quits Mono (or just runs kill -TERM <pid>), the process can receive the signal on any thread,
  2. or - if a thread in the process crashes, but the thread is not attached to the runtime, Mono's signal handlers still run.

The crash reporter assumes that the crashing thread is either attached to the runtime, or at least mono_thread_info_current or the JIT TLS data are set for the thread. If the thread is truly foreign and it never interacted with Mono, and it crashes, both of those assumptions are false, but Mono's crash reporter signal handlers still run.

The solution from this PR is: if crash reporting is enabled, start a dedicated thread at process startup that is a "crash report leader" - when a crash happens, the crashing thread (the crash originator) wakes the leader, and the leader collects the crash report. The crash originator does not do any work that requires being attached to the runtime or to the JIT such as iterating over thread IDs or stack walking.

At process startup, start a separate thread that is attached to the runtime and
can collect crash reports.  Crashing threads will wake it and wait for it to
collect the crash reports
We need to coordinate the originator and the leader in a few places.

The leader needs to pause to after collecting the thread ids before suspending
the non-originator threads, and again while the originator is dumping its own
stack.

The originator needs to wait for the leader to collect the thread IDs and to
tell it its assigned slot. Then it tells the leader to suspend the others,
dumps its own memory, then tell the leader to dump the whole crash report and
wait for it to reply when it's done.
either because the crash leader crashed, or because the process got a SIGTERM
and it arrived on the crash leader thread
It's straightline code with two early exits. State machine is overkill
@lambdageek
Copy link
Member Author

@monojenkins build failed

@lambdageek lambdageek merged commit 6303563 into mono:2020-02 Jun 24, 2021
@lambdageek lambdageek deleted the merp-dedicated-thread-2020-02 branch June 24, 2021 00:18
lambdageek added a commit to lambdageek/mono that referenced this pull request Oct 6, 2021
akoeplinger pushed a commit that referenced this pull request Oct 7, 2021
rolfbjarne added a commit to rolfbjarne/macios that referenced this pull request Dec 15, 2021
New commits in mono/mono:

* mono/mono@b8d7525156a [2020-02] [cominterop] Add coop handle enter/return on native CCW methods
* mono/mono@2ca650f1f62 [2020-02] Adds full path to libcairo for correct assembly directory resolution in monterey
* mono/mono@e750cb3ee50 [aot] Prepend the assembly name to the names of gsharedvt wrappers to avoid duplicate symbol errors during static linking.
* mono/mono@b32801a63cf Remove NuGet.config
* mono/mono@dfcef746405 Allow nfloat to be in the ObjCRuntime namespace, and make it work for Xamarin.MacCatalyst.dll as well.
* mono/mono@5ce143a1a88 Revert "[2020-02] Start a dedicated thread for MERP crash reporting (mono/mono#21126)"

Diff: https://github.com/mono/mono/compare/4150e65c9e3fb6a63afe6ac7f6ad9e90a7df971b..b8d7525156acaecf311ba468147caa74d8c190f6
rolfbjarne added a commit to dotnet/macios that referenced this pull request Dec 15, 2021
New commits in mono/mono:

* mono/mono@b8d7525156a [2020-02] [cominterop] Add coop handle enter/return on native CCW methods
* mono/mono@2ca650f1f62 [2020-02] Adds full path to libcairo for correct assembly directory resolution in monterey
* mono/mono@e750cb3ee50 [aot] Prepend the assembly name to the names of gsharedvt wrappers to avoid duplicate symbol errors during static linking.
* mono/mono@b32801a63cf Remove NuGet.config
* mono/mono@dfcef746405 Allow nfloat to be in the ObjCRuntime namespace, and make it work for Xamarin.MacCatalyst.dll as well.
* mono/mono@5ce143a1a88 Revert "[2020-02] Start a dedicated thread for MERP crash reporting (mono/mono#21126)"

Diff: https://github.com/mono/mono/compare/4150e65c9e3fb6a63afe6ac7f6ad9e90a7df971b..b8d7525156acaecf311ba468147caa74d8c190f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants