Skip to content

Process.Kill can hang indefinitely on macOS arm64 #131944

Description

@mthalman

Description

On macOS arm64, Process.Kill(entireProcessTree: true) can block indefinitely while terminating process trees created by the dotnet-watch tests.

This appeared after consuming the runtime flow containing #128598, which introduced the two-phase stop-then-kill implementation on Unix.

Enable dotnet-watch tests on mac once fixed: dotnet/sdk#55679

Reproduction Steps

  1. From a dotnet/sdk checkout at commit dc6cef6, run the dotnet-watch.Tests suite on macOS 15 arm64. In CI, this is Helix shard dotnet-watch.Tests.dll.2 on queue osx.15.arm64.open.

  2. Allow tests to dispose their child processes using Process.Kill(entireProcessTree: true).

  3. Observe that some calls never return.

A standalone runtime-only reproduction has not yet been reduced. The failure reproduces in the SDK CI shard linked below.

Expected behavior

Process.Kill(entireProcessTree: true) terminates the process tree and returns promptly.

Actual behavior

Instrumentation logged nine calls entering Process.Kill(entireProcessTree: true), but only three returned. Helix eventually detected the hang, collected dumps, and terminated the test process:

[TEST AwaitableProcess.cs:237] Killing process tree for process 18251
Hang dump timeout of '00:48:00' expired
Test application process didn't exit gracefully, exit code is '137'

One separate call returned from Kill, but its process still did not exit within 30 seconds.

Regression?

Observed after the SDK consumed the runtime flow containing #128598. That PR changed Unix process-tree termination to recursively stop the tree before killing it.

Confidence is high that the immediate hang occurs synchronously inside Process.Kill(entireProcessTree: true). Confidence that #128598 introduced the regression is moderate pending a reduced runtime-only reproduction.

Known Workarounds

None currently. Bounding the subsequent wait does not help because the call to Process.Kill itself does not return.

Configuration

  • macOS 15
  • arm64
  • Helix queue: osx.15.arm64.open
  • Work item: dotnet-watch.Tests.dll.2
  • .NET 11 runtime consumed by the SDK flow

Other information

Activity

  1. added
    untriaged
    on Aug 6, 2026
  2. dotnet-policy-service commented on Aug 6, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
    See info in area-owners.md if you want to be subscribed.

  3. adamsitnik commented on Aug 11, 2026

    @adamsitnik
    Member

    Hi @mthalman

    Thank you for a detailed bug report. I've hit hangs on macOS in #128598 but I was able to find the solution (#128598 (comment)) and get the dotnet/runtime CI green. Since then it never got stuck on macOS.

    Were you able to collect a dump locally? Or at least attach a debugger and just check which methods exactly are blocked?
    Do you happen to know if dotnet-watch.Tests.dll.2 does something unusual in terms of process management like p/invoking some native code that signs up for the SIGCHILD?

    I am asking these questions because I don't have an access to macOS arm64 machine (I will somehow try to get it, but it may take some time).

  4. added and removed
    untriaged
    on Aug 11, 2026
  5. added this to the 11.0.0 milestone on Aug 11, 2026
  6. mthalman commented on Aug 11, 2026

    @mthalman
    MemberAuthor

    This happens in Helix. I don't know much about Helix so I don't know if they capture a dump or not. But an example build is at https://dev.azure.com/dnceng-public/public/_build/results?buildId=1542039. The hang seems to be sporadic.

  7. added a commit that references this issue on Aug 20, 2026
  8. adamsitnik commented on Aug 20, 2026

    @adamsitnik
    Member

    My mac is useless as I can't netiher build dotnet/runtime nor run the installed dotnet executable (it's simply too old and not supported). I've tried creating a standalone repro, but I've failed to reproduce the problem: https://github.com/adamsitnik/macosrepro

    I suspect dotnet watch does something unusual that interferes with signal handling. I'll try to search for someone to try to debug it who has a working mac.

  9. slang25 commented on Oct 3, 2026

    @slang25
    Contributor

    Hi @adamsitnik, I think I've hit the same thing (or a close cousin of it), and I've got a small standalone repro that fails reliably on GitHub-hosted macOS runners, so hopefully that helps since getting hold of a mac is the hard part 🙂

    The twist on GitHub's runners is that it isn't just the call that blocks, the whole VM freezes. The runner loses contact with GitHub, step timeouts never fire, no logs get uploaded, and a root-owned process I left running as a canary stopped reporting at the same moment. Memory, network and file handles all looked healthy right up until it stopped.

    Repro

    repro.cs:

    using System.Diagnostics;
    
    for (var i = 1; i <= 200; i++)
    {
        using var p = Process.Start(new ProcessStartInfo("/bin/sh", ["-c", "sleep 60 & sleep 60; wait"]) { RedirectStandardOutput = true })!;
        Thread.Sleep(300);
        Console.WriteLine($"{DateTime.UtcNow:HH:mm:ss.fff} iteration {i}: killing tree of {p.Id}");
        p.Kill(entireProcessTree: true); // 💥
        p.WaitForExit();
    }
    Console.WriteLine("completed 200 iterations");

    Workflow:

    jobs:
      repro:
        strategy:
          matrix:
            os: [macos-26, macos-15]
        runs-on: ${{ matrix.os }}
        timeout-minutes: 4
        steps:
          - uses: actions/checkout@v5
          - uses: actions/setup-dotnet@v5
            with:
              dotnet-version: 10.0.x
          - run: dotnet run repro.cs

    Expected: 200 iterations, done in about a minute.

    Actual: the job never finishes and gets killed at the job timeout. That happened 4/4 times (2× macos-26, 2× macos-15, both arm64): https://github.com/slang25/glosharp/actions/runs/37140854273. It only takes the first few iterations, and the same loop runs all 200 iterations fine on my own Apple silicon mac (macOS 26), so it seems to be specific to the VMs.

    What I tried

    I swapped Kill(entireProcessTree: true) for other things in the same loop (https://github.com/slang25/glosharp/actions/runs/37138500101, https://github.com/slang25/glosharp/actions/runs/37139476351):

    Variant Froze
    Kill(entireProcessTree: true) 5/5
    Kill() 0/3
    just enumerating Process.GetProcesses() 0/3
    kill(SIGSTOP) then kill(SIGKILL) via P/Invoke 0/3
    kill(SIGSTOP), enumerate all processes, then kill(SIGKILL) 0/3
    find descendants from a ps -A -o pid=,ppid= snapshot, then kill(SIGKILL) each 0/3

    So it seems to need the full recursive stop/enumerate/kill, which I couldn't reproduce by hand. One thing that might be relevant to the regression label: we first saw this with our test host on .NET 8 and the repro above runs on .NET 10, so I don't think it's only #128598. I could be wrong about that though, I haven't tried a .NET 11 build.

    Images: macos-26-arm64 20260907.0351.1 (macOS 26.6.2) and macos-15 arm64.

    For now we've worked around it on macOS by killing the descendants from a ps snapshot instead: slang25/glosharp#117. Happy to run anything else on those runners if it'd help.

  10. thomhurst commented on Oct 12, 2026

    @thomhurst
    Contributor

    We hit this in ModularPipelines and can add another data point. It reproduces on shipped .NET 10, not just the .NET 11 flow.

    Environment: GitHub-hosted macos-latest (macos-26-arm64 image 20260907.0351.1), runtime 10.0.12 osx-arm64 installed by actions/setup-dotnet.

    Real-world impact: our command runner calls Process.Kill(entireProcessTree: true) when a cancelled command outlives its graceful-shutdown window. Our core unit tests do that many times. Since 2026-09-28 the macOS CI job froze in about 1 run in 5 (20 of 22 failed runs in one week). It always froze during the test run, and the runner reported "The hosted runner lost communication with the server". A sampler running outside the runner's process group, posting every second, showed about 81% of memory free, no swap use and a stable process count right up to the freeze.

    Repro, same loop as @slang25's above (200 iterations, kill a sh -c "sleep 60 & sleep 60; wait" tree), run 38252153698:

    Variant Froze
    Kill(entireProcessTree: true) 2/3 (jobs ran 13 min against an 8-min job timeout)
    snapshot descendants with proc_listchildpids, then Kill() the root and each descendant 0/3

    The second row matches @slang25's finding that per-process kills from a snapshot are safe. We've shipped it as a workaround on macOS (thomhurst/ModularPipelines#5927). Happy to run instrumented builds on hosted runners if that helps narrow it down.

  11. thomhurst commented on Oct 12, 2026

    @thomhurst
    Contributor

    Follow-up with captures from hosted macos-latest (runtime 10.0.12). It isn't a freeze. Every process in the caller's process group gets signalled.

    On these runners the whole job shares one process group, led by /bin/bash /opt/hca/start_hca.sh: start_hca.sh → hosted-compute-agent → Runner.Listener → Runner.Worker → step shell → the test app. Within ~40 ms of the first Kill(entireProcessTree: true), every process in that group receives SIGHUP, SIGCONT and SIGTERM. We logged these with PosixSignalRegistration in the app and trap in a sibling shell:

    14:31:32.591 iteration 1: killing tree of 1944
    14:31:32.629 received SIGTERM (cancelled)
    14:31:32.634 received SIGCONT
    14:31:32.635 iteration 1: kill returned
    14:31:32.635 received SIGHUP (cancelled)
    
    • The runner gets killed: with the handlers cancelling, the app finishes all 200 iterations, but Runner.Listener and hosted-compute-agent are gone, which is why the job "loses communication". A process table captured by a root watchdog outside the group shows the whole group gone, while ~270 other processes owned by the same user survive.
    • Its own process group avoids it: running the same app under setsid passed 3 of 3, 200 iterations each, runner alive. On a dev machine the terminal puts each command in its own group, which would explain why it never reproduces there.
    • The SIGSTOP looks like the trigger: SIGHUP followed by SIGCONT matches the orphaned-process-group rule, where the kernel signals a group that becomes orphaned while it has stopped members. KillTree SIGSTOPs each process before killing it. A snapshot of descendants followed by a plain SIGKILL of each process never triggers it (0 of 3, and 0 of 15+ in our CI). We haven't found where the SIGTERM comes from; it may be the runner agent shutting down its group after the SIGHUP.
    • Not just the new code: 10.0.12 still has the old single-pass KillTree (stop, enumerate, kill, recurse), not the Fix Process.Kill(entireProcessTree: true) when intermediate child has KillOnParentExit #128598 rewrite.

    Captures (process tables before and after, system-wide spindump, watchdog logs, heartbeats): https://github.com/thomhurst/ModularPipelines/releases/tag/diag-runtime-131944. Workflow and repro: https://github.com/thomhurst/ModularPipelines/tree/diag/macos-runner-loss/diag. A heap dump isn't possible because the app is killed before anything can attach.

  12. added a commit that references this issue on Oct 13, 2026
    fbf6683
  13. adamsitnik commented on Oct 13, 2026

    @adamsitnik
    Member

    I need to keep this issue opened until we get #135409 backported to 11 and prepare the fix for 10 as well (I am going to take care of that).

  14. added a commit that references this issue on Oct 14, 2026
  15. added a commit that references this issue on Oct 30, 2026
  16. added a commit that references this issue on Oct 30, 2026
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

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions