Skip to content

Fix macOS CI freezes caused by Process.Kill(entireProcessTree) - #117

Merged
slang25 merged 3 commits into
mainfrom
slang25/fix-macos-ci-freeze
Oct 3, 2026
Merged

slang25 merged 3 commits into
mainfrom
slang25/fix-macos-ci-freeze

Conversation

@slang25

@slang25 slang25 commented Oct 3, 2026

Copy link
Copy Markdown
Owner

The intermittent macOS CI hang (stuck in Test until the job timeout, no logs, step timeout and --hangdump never firing) was the runner VM itself freezing. The trigger was Process.Kill(entireProcessTree: true), which Run_Timeout_KillsProcessTree calls when its 1s timeout fires.
On macOS, ProcessRunner now kills descendants from a ps snapshot instead; other platforms keep the built-in tree kill, and the kill-tree test now asserts the grandchildren are actually gone.
Evidence from scratch CI runs: a stress loop with Kill(entireProcessTree: true) froze macos-26 VMs within seconds 5/5 times, the same churn with plain kill / enumeration / SIGSTOP+SIGKILL / snapshot kill froze 0/15, and the full suite with this fix passed 12/12 (10 macos-26, 2 macos-15) against a 25–50% freeze rate before.
Also corrects the comments that blamed the freezes on memory and the NuGet cache.

🤖 Generated with Claude Code

The intermittent macOS CI hang (job stuck in "Test" until the job
timeout, no logs, step timeout and --hangdump never firing) was the
runner VM itself freezing, triggered by Process.Kill(entireProcessTree:
true). ProcessRunnerTests.Run_Timeout_KillsProcessTree hits its 1s
timeout and kills a shell tree; depending on timing, the whole VM
locked up, root processes included.

Diagnosed on scratch CI runs with a root-owned canary and an in-flight
test trace: memory, network and file handles were healthy at every
freeze, and the kill-tree test was in flight. A stress loop calling
Process.Kill(entireProcessTree: true) froze macos-26 VMs within
seconds 5/5 times; the same churn with plain Kill, process
enumeration, SIGSTOP+SIGKILL, or killing descendants from a ps
snapshot froze 0/15. It also reproduced on macos-15.

On macOS, ProcessRunner now snapshots descendants with ps and SIGKILLs
them; other platforms keep the built-in tree kill. The kill-tree test
now also asserts the grandchildren are gone. Corrected the comments
that blamed the freezes on memory and the NuGet cache.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Process-exit races and an ineffective ps timeout can still leak descendants or hang timeout handling.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds a macOS-specific process-tree termination workaround to prevent CI runner freezes.

Changes:

  • Uses a ps snapshot to terminate descendants on macOS.
  • Strengthens timeout process-tree tests.
  • Corrects CI freeze documentation.
File Description
src/​GloSharp.Core/​ProcessRunner.cs Adds macOS snapshot-based termination.
tests/​GloSharp.Tests/​ProcessRunnerTests.cs Verifies spawned processes terminate.
tests/​GloSharp.Tests/​AssemblyInfo.cs Corrects memory-limit commentary.
.github/​workflows/​ci.yml Corrects cache-related commentary.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/GloSharp.Core/ProcessRunner.cs Outdated
private static void KillTreeFromSnapshot(Process process)
{
var descendants = Descendants(process.Id);
process.Kill();
Comment on lines +50 to +60
var result = await ProcessRunner.RunAsync("/bin/sh", ["-c", "sleep 60 & echo $!; sleep 60 & echo $!; wait"], timeout: TimeSpan.FromSeconds(1));
stopwatch.Stop();

await Assert.That(result.TimedOut).IsTrue();
await Assert.That(result.Succeeded).IsFalse();
await Assert.That(stopwatch.Elapsed).IsLessThan(TimeSpan.FromSeconds(30));

var grandchildren = result.StandardOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
await Assert.That(grandchildren.Count).IsEqualTo(2);
foreach (var pid in grandchildren)
await Assert.That(await IsGoneAsync(pid)).IsTrue();
- Catch the root exiting between the snapshot and Kill(), so captured
  descendants are still killed instead of leaking with the pipes
- Read ps output on a dedicated thread with a real 5s limit; the old
  WaitForExit(5000) after ReadToEnd() could never time out
- Kill-tree test now nests a shell, so it covers more than one
  generation of descendants (fails if the traversal isn't recursive)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@slang25
slang25 merged commit 858dc51 into main Oct 3, 2026
7 checks passed
@slang25
slang25 deleted the slang25/fix-macos-ci-freeze branch October 3, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants