Skip to content

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

Closed

Description

@baal2000

Description

A .NET 9 application running as the primary process (PID 1) in a Docker container fails to terminate after an unhandled exception. The runtime correctly generates a crash dump as configured by DOTNET_DbgEnableMiniDump=1, but immediately afterward the process continues running instead of exiting.

Reproduction Steps

Update: the reproduction has been moved to its own repo at TestUnhandledCrashConsoleApp.

The following minimal application and Docker configuration reproduces the issue.

Step 1: C# Application Code (Program.cs) triggers an unhandled exception on a timer thread after 10 seconds.

AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
    Console.WriteLine("Unhandled exception: " + e.ExceptionObject.ToString());
};

using var timer = new Timer(
    callback: _ => throw new InvalidOperationException("This is a test exception"),
    state: null,
    dueTime: TimeSpan.FromSeconds(10),
    period: Timeout.InfiniteTimeSpan
);

Console.WriteLine("Hello, World! Application will crash in 10 seconds...");
// Keep the application running
Thread.Sleep(Timeout.Infinite);

Step 2: Publish the application as a self-contained executable for the Linux x64 runtime.

dotnet publish -c Release -r linux-x64

Step 3: Dockerfile
Create a Dockerfile to package the application.

# Use the official .NET 9 runtime base image
FROM mcr.microsoft.com/dotnet/aspnet:9.0

# Set the working directory inside the container
WORKDIR /app

# Copy the published application files into the container
COPY ./bin/Release/net9.0/linux-x64/publish/ .

# Set the entrypoint to run the application.
# Using this "exec" form ensures the app runs as PID 1.
ENTRYPOINT ["./YourAppName"]

(Note: Replace YourAppName with the actual name of the project's executable.)

Step 4: Build the image and run containers demonstrating the different behaviors.

docker build -t pid1-crash-app .

Step 5: Execute the following test cases:

A. FAILS: Application crashes, creates a dump, and then hangs.

docker run --rm -v ~/Downloads:/dumps -e "DOTNET_DbgEnableMiniDump=1" -e "DOTNET_DbgMiniDumpType=1" -e "DOTNET_DbgMiniDumpName=/dumps/coredump.%p" pid1-crash-app

B. PASSES: Application crashes and exits correctly (no dump created).

docker run --rm -v ~/Downloads:/dumps -e "DOTNET_DbgEnableMiniDump=0" -e "DOTNET_DbgMiniDumpType=1" -e "DOTNET_DbgMiniDumpName=/dumps/coredump.%p" pid1-crash-app

C. PASSES: Application is not PID 1, creates a dump, and exits correctly.

docker run --rm --init -v ~/Downloads:/dumps -e "DOTNET_DbgEnableMiniDump=1" -e "DOTNET_DbgMiniDumpType=1" -e "DOTNET_DbgMiniDumpName=/dumps/coredump.%p" pid1-crash-app

TestUnhandledCrashConsoleApp.zip

Expected behavior

Test Case A PASSES: Application is PID 1, creates a dump, and exits correctly.

Actual behavior

Test Case A FAILS: Application crashes, creates a dump, and then hangs.

Regression?

Yes.

A .NET 8 - based application passes all 3 tests successfully.

Known Workarounds

This behavior does not occur under the following conditions:

  • When DOTNET_DbgEnableMiniDump is set to 0.
  • When the container is run with an init system (e.g., using the docker run --init flag), which prevents the application from running as PID 1.

Configuration

  • .NET Version: .NET 9
  • Operating System: Linux (Ubuntu 20.04, etc)
  • Deployment: An application running in a Docker container.

Other information

STRACE Analysis: Attached strace.txt from a sidecar container.
strace -f -e trace=signal -p 1

  1. Successful Dump Creation: strace logs confirm that the .NET runtime successfully launches the createdump utility and is notified of its completion via the SIGCHLD signal.
[pid  4633] +++ exited with 255 +++
[pid  1102] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4633, si_uid=5001, si_status=255, si_utime=0, si_stime=9 /* 0.09 s */} —
  1. Failed Termination Sequence: After the dump is complete, the strace log shows a dedicated crash-handling thread pid 4094 attempting to terminate the application by sending a SIGABRT signal twice to itself. This signal is "swallowed" and the process does not terminate.
[pid  4094] --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=1, si_uid=5001} ---
[pid  4094] rt_sigaction(SIGABRT, {sa_handler=SIG_DFL, sa_mask=~[], sa_flags=SA_RESTORER, sa_restorer=0x7e87a0a78090}, NULL, 8) = 0
[pid  4094] rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
[pid  4094] tgkill(1, 4094, SIGABRT)    = 0
[pid  4094] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid  4094] --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=1, si_uid=5001} ---
  1. State Corruption and SIGSEGV: Immediately after the failed SIGABRT attempts, the crash-handling thread receives a SIGSEGV (Segmentation Fault), indicating its memory state has become corrupted.
[pid  4094] --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=NULL} ---

gdb Analysis:

  1. A gdb backtrace of the hung process confirms the cause of the SIGSEGV is a call to __netlink_request with a null pointer (h=0x0).
Thread 238 (LWP 4094):
#0  0x00007e87a0b47bbf in __netlink_request (h=0x0, type=<optimized out>) at ../sysdeps/unix/sysv/linux/ifaddrs.c:119
  1. The gdb command info handle SIGABRT shows the default handler is registered (yet strace shows the signal is not handled correctly).
 (gdb) info handle SIGABRT
Signal        Stop	Print	Pass to program	Description
SIGABRT       Yes	Yes	Yes		Aborted

Activity

  1. added
    untriaged
    on Jul 25, 2025
  2. added
    needs-area-label
    on Jul 25, 2025
  3. added
    area-ExceptionHandling-coreclr
    and removed
    needs-area-label
    on Jul 25, 2025
  4. removed
    untriaged
    on Jul 25, 2025
  5. added this to the Future milestone on Jul 25, 2025
  6. mangod9 commented on Jul 25, 2025

    @mangod9
    Member

    Adding @janvorli. I believe this is a known issue but I can't find a previous issue for this. @baal2000, is this a regression in 9?

  7. mangod9 commented on Jul 25, 2025

    @mangod9
    Member

    This is the original issue: #112580

  8. baal2000 commented on Jul 25, 2025

    @baal2000
    Author

    is this a regression in 9

    yes if we compare with 8. #109779 looks like a similar problem (mentions the crashdump triggering the issue) and has been fixed in 10 then the fix needs to be ported back to 9.

  9. baal2000 commented on Jul 26, 2025

    @baal2000
    Author

    The reproduction for both 9.0 and 10.0 frameworks has been moved to ist own repo TestUnhandledCrashConsoleApp. Can also be updated to 8.0 if needed.

    I have tested with 10.0 preview 6, confirmed it has fixed the issue.

  10. baal2000 commented on Jul 28, 2025

    @baal2000
    Author

    @janvorli @mikem8361 #110379 for #109779 is what likely fixes the bug: looks simple enough to back-port to .NET 9 so that customers do not have to worry about workarounds.
    The reproduction is available so it is going to be easy to validate if the fix works.

  11. baal2000 commented on Jul 30, 2025

    @baal2000
    Author

    @mangod9 please ask the team to decide whether this is going to be fixed by porting back from .net 10 preview. This is a deal or no deal regarding .net 9 for us: disabling crash dumps is not a nice option and changing the build process is risky and looks unnecessary if it can be addressed in the framework. Thank you.

  12. mangod9 commented on Jul 30, 2025

    @mangod9
    Member

    Adding @steveisok @tommcdon since this was fixed via #110379. We will evaluate porting to 9. Thx.

  13. mangod9 commented on Aug 13, 2025

    @mangod9
    Member

    @steveisok @tommcdon do you see any concerns of back porting the fix to 9?

  14. 7 remaining items

  15. jkotas commented on Oct 21, 2025

    @jkotas
    Member

    Off the top of my head, I wouldn't expect Environment.FailFast to hit PROCCreateCrashDump. Seems like a different issue.

    Environment.FailFast is expected to generate crash dump just like unhandled exception or other kinds of abnormal program termination.

  16. baal2000 commented on Oct 22, 2025

    @baal2000
    Author

    Per #120936:

    On x64 linux the expected behavior was observed.

    I haven't mentioned that #118049 (comment) test has only been done on x64 linux / .NET 10

  17. ladeak commented on Oct 23, 2025

    @ladeak
    Contributor

    Off the top of my head, I wouldn't expect Environment.FailFast to hit PROCCreateCrashDump. Seems like a different issue.

    Environment.FailFast is expected to generate crash dump just like unhandled exception or other kinds of abnormal program termination.

    It does generate a procdump, but only the first occurrence, and the application keeps running.

  18. ronin1 commented on Mar 24, 2026

    @ronin1

    If you're struggling with this, just wrap your app main entry function with a try catch & force an env exit (any code that's not 0) like this:

    Original Code

    var app = builder.Build();
    app.Run();
    // cleanup, flush log, etc
    

    Patched Code

    try {
      var app = builder.Build();
      app.Run();
    
      // cleanup, flush log, etc
    
    } catch(Exception e) {
      logger.Fatal(e, "App Crash .... ");
    
      // cleanup, flush log, etc
    
      Environment.Exit(1); // this throw the correct linux sigterm, as long as the value is not 0
    }
    

    This should still work when the container/runtime is patched later.

    It happened on the official MS container for us: mcr.microsoft.com/dotnet/aspnet:9.0-noble-chiseled with OpenTelemetry v1.15.0

  19. dotnet-policy-service commented on Apr 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke
    See info in area-owners.md if you want to be subscribed.

  20. NicolasDorier commented on Nov 3, 2026

    @NicolasDorier

    Cross-reporting a production report from an NBXplorer user that may be relevant to the ARM64/PID-1 behavior discussed here: btcpayserver/NBXplorer#576.

    Reported environment: NBXplorer 2.6.21, .NET 10.0.14, Ubuntu 24.04, linux/arm64, running in Kubernetes with dotnet NBXplorer.dll as PID 1.

    A Postgres startup race caused an NpgsqlException to escape the application's async Main unhandled. After logging Unhandled exception, the process did not exit. According to the reporter, 80 minutes later the container still had zero restarts and had consumed 78 minutes of CPU, all on the main thread. The reporter provided this excerpt from /proc/1/task/1/status:

    State:  R (running)
    SigPnd: 0000000000000010              # SIGTRAP pending
    voluntary_ctxt_switches:     51
    nonvoluntary_ctxt_switches:  1580503
    

    The symptoms closely resemble the PID-1 / glibc abort() / ARM64 SIGTRAP loop explained in #66707 (comment). In the v10.0.14 source, PROCAbort calls SEHCleanupSignals(false) and then abort(), while SEHCleanupSignals(false) restores only SIGABRT, leaving the SIGTRAP handler installed. This is consistent with that explanation, but is not proof of the precise cause in this deployment.

    We merged an application-level workaround in btcpayserver/NBXplorer#577: retry transient database startup failures and catch fatal exceptions at Main, log them, and return exit code 1 instead of entering the unhandled-exception abort path.

    Verification limits: We have not independently reproduced the original hang on .NET 10.0.14 ARM64. Our validation used .NET 10.0.14 Linux/amd64 with dotnet as PID 1 and confirmed that the workaround exits with code 1 on fatal startup errors. The original report does not specify the DOTNET_DbgEnableMiniDump setting or establish whether a crash dump was generated, and does not include an --init comparison or a minimal runtime-only reproduction.

    Is the ARM64 behavior reported here still covered by this issue, or would a separate issue/reproduction be more useful? The linked NBXplorer report contains the startup stack trace and additional deployment details.

  21. birdnamoo commented on Nov 19, 2026

    @birdnamoo

    One more data point for the PID 1 / unhandled-exception case, on a current runtime.

    • Image: mcr.microsoft.com/dotnet/runtime:10.0 (Microsoft.NETCore.App 10.0.15), linux/arm64 (Docker in a Linux VM on Apple silicon).
    • App: a published net10.0 console app whose only statement is throw new InvalidOperationException("boom");.
    • docker run -d (dotnet as PID 1, no init): the exception and stack trace are printed, then the container stays Up at about 100 % CPU (/proc/1/status: State: R, 6 threads), still so after 10 seconds. docker stop ends it (SIGTERM is handled).
    • Same image with docker run --init (Compose init: true): the process terminates right after the report, exit code 134.
    • Catching the exception and returning an exit code ends the process normally in both cases.

    Not checked: x64, bare-metal arm64, other runtime versions.

  22. gao-artur commented on Nov 23, 2026

    @gao-artur

    Will it be backported to .NET 10?

  23. added a commit that references this issue on Nov 23, 2026
    eea42a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Relationships

None yet

Development

No branches or pull requests

Issue actions