Skip to content

Ghostty.Bench: harden process cleanup on Windows (JobObject + WtLauncher doc) #335

Description

@deblasis

Follow-up from a wintty-bench containment audit (see deblasis/wintty-bench#5). wintty-bench now wraps its launched Wintty process in a Windows JobObject with KILL_ON_JOB_CLOSE, which catches orphan shells re-parented to PID 0 on abort. The audit found two latent spots in this repo that don't leak today but would silently break under plausible future changes.

1. Ghostty.Bench/Transports/DirectPipeTransport.cs

Spawns EchoChild.exe via Process.Start and cleans up with Process.Kill(entireProcessTree: true) around line 58. EchoChild is a leaf binary today with no grandchildren, so the Kill works. If anyone replaces EchoChild with a shell wrapper (pwsh/cmd) the cleanup silently fails on Windows because entireProcessTree walks parent-PID links at kill time, and re-parented orphans are unreachable.

Fix: wrap the Process in a JobObject before Process.Start and dispose the job on cleanup. Reference implementation: harness/Launchers/WinttyJobObject.cs in deblasis/wintty-bench. About 30 lines of P/Invoke plus an assign-at-start line.

2. harness/Launchers/WtLauncher.cs (wintty-bench)

Not actually in this repo, but worth calling out for symmetry: WtLauncher launches Windows Terminal via its MSIX entry, and MSIX apps cannot be added to a JobObject. It already degrades to Process.Kill(entireProcessTree) via LaunchHandle.Dispose, which is the best we can do. A one-line code comment noting the MSIX constraint would prevent anyone pattern-matching against WinttyLauncher and filing this as a bug.

Will file the WtLauncher comment in deblasis/wintty-bench directly; this issue tracks only item # 1.

Priority

Low. No observed leaks. Nice-to-have hardening for future-proofing the ConPTY bench harness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ciNon-automated GitHub Actions changesenhancementNew feature or requestos/windows

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions