Repository navigation
fix(install): end a gh shim's lingering child with the Windows star check - #1073
Merged
Merged
Conversation
…heck Invoke-GhApi killed only the launcher PID on its deadline. A gh .cmd shim's launcher has often exited by then, and taskkill /T finds no tree under an exited PID, so a child that kept gh's output open lived on, and on .NET Framework Dispose left the pipe readers open. gh now runs in a job object with KILL_ON_JOB_CLOSE (Add-Type P/Invoke, works on Windows PowerShell 5.1), created before gh starts and closed on the deadline and in finally; the output and error readers are closed there too. Without a job the old taskkill path still runs. scripts/windows-install.test.ps1 extracts Invoke-GhApi by AST and runs it against a gh.cmd stand-in that leaves a ping holding its output; the child's PID must be gone after the call (regression, fails on main). Closes #558
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fix the blocking PR #1073 start-before-assignment finding by creating gh suspended with redirected pipes, assigning its job, then resuming it. Pin the race with an immediate-child Windows shim and a forced runnable-launch negative control.
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.
Fixes #558
Root cause
install.ps1Invoke-GhApi(origin/main L123-154): when gh is a.cmd/.batshim run throughcmd.exe, the shim can start a child that inherits the stdout pipe and then exit.WaitForExitsucceeds,$said.Wait(2000)times out, and the timeout branch (L148) runstaskkill /T /Fon the launcher PID, which has already exited and has no tree left. The child lives on. Thefinally(L154) only calledProcess.Dispose(), which on Windows PowerShell's .NET Framework leaves the StandardOutput/StandardError readers open.What changed
install.ps1: before gh starts,Invoke-GhApicreates a job object withJOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSEthroughAdd-TypeP/Invoke (PowerShell 5.1 compatible, compiled once per session, only when gh is present). It assigns the launched process to the job right afterProcess.Start. On a timeout, closing the job ends gh and every process it started, even one whose parent has exited. The job is also closed infinally. Both pipe readers are closed explicitly, and the close is guarded against a pendingReadToEndAsync. IfAdd-Type, job creation or assignment fails, the previoustaskkill /Tpath runs unchanged.scripts/windows-install.test.ps1: adds alingeringmode to the gh stand-in. It answers, then leaves apingchild holding its output and writes that child's PID. The new case extracts onlyInvoke-GhApifrom the installer through a PowerShell AST parse, calls it, and asserts the child is gone. Assertions are labelledcontrol(the stand-in named its child; the call returned nothing within 15 s) orregression (fails on main)(the child does not outlive the call).changelog.d/install-ps1-gh-job-object.md: Fixed entry.Not covered: the two Low notes in the issue about
install.sh's gh watcher (a briefly orphanedsleep 1and PID-only identification). Neither is part of this Windows fix.Residual: a process gh starts in the instant between
Process.StartandAssignProcessToJobObjectis not in the job, becauseProcess.Startcannot start suspended. Thetaskkillfallback still covers a live launcher.Evidence
On the Windows QA PC (Windows 11, PowerShell 5.1), in a fresh clone of this branch:
scripts\windows-install.test.ps1exits 0 withPASS gh deadline: a child of gh that holds its output ends with the call (PID …, 3 s). The existing native installer, star and herdr installer cases still pass.install.ps1from origin/main, same test): exits 1 withregression (fails on main): the child gh left holding its output (PID …) must not outlive the call. Both controls pass. The surviving child was confirmed alive until the test killed it.ping, no stand-in temp directories, clone removed.Checks run
bun run typecheck: exit 0HERDR_TEST_MODE=unit bun test ./scripts/changelog-fold.test.ts ./scripts/install-star.test.ts ./scripts/conventions.test.ts: 43 pass, 0 failbun run test:unit: 3515 pass, 0 fail, 8 skippedgit diff --check: cleanpowershell -File scripts\windows-install.test.ps1on Windows: pass on the branch, regression failure with main's installer (above)