Skip to content

Job steps share an orphaned process group with Runner.Listener, so a step can kill the runner #4775

Open

Description

@thomhurst

Describe the bug
Runner.Worker runs job steps in the same process group as Runner.Listener and whatever supervises it. When that group is orphaned, as it is on hosted macOS runners, a step can get the runner killed. The kernel sends SIGHUP and SIGCONT to the whole group, so Runner.Listener and hosted-compute-agent die. The job then ends with "The hosted runner lost communication with the server", step timeouts never fire and the logs are lost.

Process ancestry of a step shell on hosted macos-latest. The third column is the process group ID (pgid):

 1908  1002   967 runner /bin/bash -e /Users/runner/work/_temp/....sh
 1002   997   967 runner .../Runner.Worker spawnclient 143 146
  997   980   967 runner .../Runner.Listener run
  980   967   967 runner /opt/hca/hosted-compute-agent
  967     1   967 runner /bin/bash /opt/hca/start_hca.sh

The group leader's parent is launchd, so the group is orphaned. If a member exits while another member is stopped, POSIX has the kernel send SIGHUP followed by SIGCONT to every process in the group. .NET's Process.Kill(entireProcessTree: true) SIGSTOPs each process before killing it, which is enough to trigger this. Within about 40 ms of the call, every process in the group received SIGHUP, SIGCONT and SIGTERM. We logged these with signal handlers in the app and with trap in a sibling shell.

To Reproduce

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);
    p.Kill(entireProcessTree: true);
    p.WaitForExit();
}
Console.WriteLine("completed 200 iterations");

Workflow:

jobs:
  repro:
    runs-on: macos-latest
    timeout-minutes: 8
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-dotnet@v5
        with:
          dotnet-version: 10.0.x
      - run: dotnet run repro.cs

Run in the shared group, this killed the runner in 10 of 13 jobs. The same repro run in its own session and process group (os.setsid() before exec) passed 3 of 3, with the runner still alive.

Expected behavior
The worst a step should be able to do is fail or hang itself, so the step timeout fires and the logs are uploaded. Signals sent to a step's process group, whether by a tool or by the kernel, should not reach Runner.Listener or its supervisor.

Runner Version and Platform

The runner shipped in hosted macos-26-arm64 image 20260907.0351.1 (macOS 26.6.2), and also in macos-15 arm64. The steps used .NET runtime 10.0.12.

The cause is not specific to macOS. Any runner without a controlling terminal whose process group is orphaned has the same layout.

What's not working?

"The hosted runner lost communication with the server". The job runs until the job timeout.

Job Log Output

None. The runner is killed before the logs are uploaded.

Runner and Worker's Diagnostic Logs

Not available from hosted runners. A root-owned watchdog outside the group captured process tables before and after, a system-wide spindump and signal logs: https://github.com/thomhurst/ModularPipelines/releases/tag/diag-runtime-131944

Workflow and repro: https://github.com/thomhurst/ModularPipelines/tree/diag/macos-runner-loss/diag

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions