Repository navigation
Fix macOS CI freezes caused by Process.Kill(entireProcessTree) - #117
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
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
Open (2)
What changed in this PR
Adds a macOS-specific process-tree termination workaround to prevent CI runner freezes.
Changes:
- Uses a
pssnapshot 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.
| 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The intermittent macOS CI hang (stuck in
Testuntil the job timeout, no logs, step timeout and--hangdumpnever firing) was the runner VM itself freezing. The trigger wasProcess.Kill(entireProcessTree: true), whichRun_Timeout_KillsProcessTreecalls when its 1s timeout fires.On macOS,
ProcessRunnernow kills descendants from apssnapshot 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)frozemacos-26VMs 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 (10macos-26, 2macos-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