Skip to content

Restore SIGTRAP before abort() so the process can exit as PID 1 - #137998

Merged
jkotas merged 2 commits into
dotnet:mainfrom
steveisok:steveisok-pid1-abort-sigtrap-hang
Nov 23, 2026
Merged

jkotas merged 2 commits into
dotnet:mainfrom
steveisok:steveisok-pid1-abort-sigtrap-hang

Conversation

@steveisok

@steveisok steveisok commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #118049

Problem

A .NET process running as PID 1 in a container, without an init process such as docker run --init, can hang at 100% CPU after an unhandled exception or Environment.FailFast, instead of exiting. This affects Linux architectures where glibc's abort() fallback instruction raises SIGTRAP (arm64, loongarch64, riscv64) with glibc older than 2.41 (for example Ubuntu 22.04/24.04 and Debian 12) on .NET 9, 10 and 11. It happens with and without DOTNET_DbgEnableMiniDump.

Cause

In .NET 9, #105578 changed SEHCleanupSignals(false), which PROCAbort calls just before abort(), so that it restores only SIGABRT. Before that, all handlers were restored, which is how #66707 was fixed in .NET 8.

The kernel ignores a SIGABRT that PID 1 sends itself when the handler is the default. glibc's abort() then falls back to a trap instruction (brk #1000 on arm64). The trap raises SIGTRAP. The runtime's SIGTRAP handler is still installed, and it returns to the same brk instruction, so the process spins forever.

Why only older glibc: glibc 2.41 rewrote abort() (BZ 26275) and now blocks all signals before it runs the trap instruction. When a trap fires while its signal is blocked, the kernel can't call our handler. Instead it forces the default action, which terminates the process even as PID 1, with exit code 133. Older glibc leaves signals unblocked, so our handler runs and the loop starts. Newer distros (for example Ubuntu 26.04, which the .NET 11 container images use) mask the runtime bug; they don't fix it.

On x64 the fallback (hlt) raises SIGSEGV, which already exits after #110379. On arm32, ppc64le and s390x it raises SIGILL, whose handler likewise restores the default and re-runs the instruction.

riscv64 (ebreak) and loongarch64 (break 0) also fall back to a SIGTRAP-raising trap, so they're expected to hit the same hang. This change covers them too. musl (Alpine) isn't affected, because its abort() blocks all signals before the trap.

Fix

Restore SIGTRAP together with SIGABRT in the abort path of SEHCleanupSignals (Linux/FreeBSD only; macOS uses Mach exceptions). The other hardware exception handlers stay installed, so #46175 (fixed by #105578) is not reintroduced. The SIGTRAP restore in the child-process path is now covered by the shared block.

Validation

I built linux-arm64 libcoreclr.so from v11.0.0, with and without this change. Each build ran as PID 1 in an Ubuntu 24.04 (glibc 2.39) container, with an app that throws an unhandled exception:

Before After
PID 1 hangs (100% CPU) exits (133)
PID 1 + DOTNET_DbgEnableMiniDump=1 dump written, then hangs dump written, exits (133)
--init exits (134) exits (134)

There is no automated test: PID 1 signal behavior needs a dedicated PID namespace (container), which our test infrastructure doesn't provide.

Note

This PR description was drafted with GitHub Copilot.

When PROCAbort calls abort() and SIGABRT does not terminate the process
(e.g. the process is PID 1 in a container, where the kernel drops
SIGABRT with the default disposition), glibc < 2.41 falls back to its
ABORT_INSTRUCTION. On arm64 that is `brk`, which raises SIGTRAP. The
runtime's sigtrap_handler was still installed, returned to the same brk,
and the process spun forever at 100% CPU instead of exiting.

Restore the original SIGTRAP disposition along with SIGABRT in
SEHCleanupSignals so the kernel terminates the process.

Co-authored-by: Copilot App <[email protected]>
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label Nov 20, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🔵 Needs a closer look

The process-wide fatal-signal changes affect a path with a prior concurrent-crash regression, requiring maintainer confirmation of reported older-glibc ARM64/PID-1 validation and concurrency coverage that could not be independently exercised.

No open issues 🎉

What changed in this PR

This PR addresses the PID 1 shutdown hang in #118049 by restoring SIGTRAP before CoreCLR calls abort(), allowing its fallback trap to terminate the process on affected Linux systems.

Changes:

  • Restore SIGTRAP alongside SIGABRT on platforms without Mach exceptions, sharing the restoration with child-process cleanup.
  • Keep other hardware exception handlers installed during abort to preserve concurrent-crash handling.
  • Update the PROCAbort comment to describe the selective signal restoration accurately.
File Description
src/​coreclr/​pal/​src/​thread/​process.cpp Corrects the comment describing signal cleanup before abort().
src/​coreclr/​pal/​src/​exception/​signal.cpp Moves SIGTRAP restoration into shared cleanup and explains the PID 1 fallback-trap behavior.

Review effort: Balanced

@jkotas

jkotas commented Nov 23, 2026

Copy link
Copy Markdown
Member

/ba-g dead letter

@jkotas
jkotas merged commit eea42a5 into dotnet:main Nov 23, 2026
101 of 103 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-PAL-coreclr only for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET 9 Process Fails To Terminate after Unhandled Exception when running as PID 1 in Docker with Crash Dump enabled

3 participants