Skip to content

[Diagnostics] Serialize concurrent reporters in InProc Crash Reporter#130436

Open
mdh1418 wants to merge 1 commit into
dotnet:mainfrom
mdh1418:inproc_crashreport_multisignal_race
Open

[Diagnostics] Serialize concurrent reporters in InProc Crash Reporter#130436
mdh1418 wants to merge 1 commit into
dotnet:mainfrom
mdh1418:inproc_crashreport_multisignal_race

Conversation

@mdh1418

@mdh1418 mdh1418 commented Jul 9, 2026

Copy link
Copy Markdown
Member

CreateReport() uses a CAS guard so only the first thread generates the crash report. Losing threads previously returned immediately, then continued through PROCAbort() -> abort(), tearing down the process while the winner was still mid-report and truncating it.

On the common fatal-signal path this is already prevented upstream (EEPolicy::LogInfoForFatalError and the stack-overflow guard block losers before they reach the in-proc reporter). It can still be entered concurrently via direct PROCAbort paths that bypass those guards (e.g. exception-record pool exhaustion, FATAL_ASSERT, RaiseFailFastException). createdump's serialize=true path already blocks losers, but PROCCreateCrashDumpIfEnabled short-circuits into the in-proc callback and skips it, so the in-proc reporter must serialize itself.

Mirror createdump: one InterlockedCompareExchange64 claims the guard and records the owner. Losers block in poll() until the winner's abort() tears the process down; a re-entrant fatal signal on the winning thread bails out instead of deadlocking. All threads are already captured in the winner's report, so there is no information loss.

…aths

CreateReport() uses a CAS guard so only the first thread generates the crash
report. Losing threads previously returned immediately, then continued through
PROCAbort() -> abort(), tearing down the process while the winner was still
mid-report and truncating it.

On the common fatal-signal path this is already prevented upstream
(EEPolicy::LogInfoForFatalError and the stack-overflow guard block losers
before they reach the in-proc reporter). It can still be entered concurrently
via direct PROCAbort paths that bypass those guards (e.g. exception-record
pool exhaustion, FATAL_ASSERT, RaiseFailFastException). createdump's
serialize=true path already blocks losers, but PROCCreateCrashDumpIfEnabled
short-circuits into the in-proc callback and skips it, so the in-proc reporter
must serialize itself.

Mirror createdump: one InterlockedCompareExchange64 claims the guard and
records the owner. Losers block in poll() until the winner's abort() tears the
process down; a re-entrant fatal signal on the winning thread bails out instead
of deadlocking. All threads are already captured in the winner's report, so
there is no information loss.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e9f8de07-6c05-4570-9f33-90bce6550391
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 changes the CoreCLR in-proc crash reporter’s CreateReport entry guard to serialize concurrent invocations so that only one thread generates the crash report while other threads block, avoiding report truncation when multiple fatal paths race to abort the process.

Changes:

  • Replace the previous one-shot InterlockedCompareExchange guard with a 64-bit thread-id CAS guard.
  • Block “losing” threads in CreateReport instead of returning immediately, to prevent them from continuing to PROCAbort() while the report is still being written.

Comment on lines +607 to +611
static LONGLONG s_generatingThreadId = 0;

// INFTIM is not defined when including pal.h; -1 is the equivalent poll() "wait forever" timeout.
const int PollWaitForever = -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateDump have a serialize flag that gets set through PROCCreateCrashDumpIfEnabled when called from a location that should serialize the threads, we should use the same flag here.

@lateralusX lateralusX Jul 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to consider, in case we call in-proc crash reporter from invoke_previous_action and g_crash_report_before_signal_chaining has been enabled, we get called before chained signal handlers gets called. The scenario is explicitly created when you have a signal handler that is not DFL, but always tear downs the process, like calling the debugger daemon on Android, serializing the in-proc crash reporters in that case is probably OK, since no other crash handlers should appear in the chain, but if they do, then we can't serialize threads, since they need to call the chained signal handler and we might create an in-proc report for something that ends up being a handled signal. So, g_crash_report_before_signal_chaining can't be used unless the app explicitly knows that any signal handler won't handle the signal, because it will then have blocked all other threads from reaching that point and produced a "false" in-proc crash report. On Android this is normally fine, since the debugger daemon signal handler is in the list, but there is no guarantee there won't be a signal handler before that that would handle/ignore it. In scenarios like that the only reasonable way is to not using g_crash_report_before_signal_chaining and let the chained signal handler run first, but on Android that will lead to debugger daemon signal handler terminating the process before any in-proc crash reports have been generated.

Copilot AI review requested due to automatic review settings July 9, 2026 21:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines +609 to +624
// INFTIM is not defined when including pal.h; -1 is the equivalent poll() "wait forever" timeout.
const int PollWaitForever = -1;

LONGLONG currentThreadId = static_cast<LONGLONG>(minipal_get_current_thread_id());
LONGLONG previousThreadId = InterlockedCompareExchange64(&s_generatingThreadId, currentThreadId, 0);
if (previousThreadId != 0)
{
return;
if (previousThreadId == currentThreadId)
{
return;
}

while (true)
{
poll(nullptr, 0, PollWaitForever);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants