Skip to content

test: tolerate a process already gone when cleaning up the git timeout test - #334

Merged
mindsers merged 2 commits into
developfrom
bugfix/flaky-git-timeout-test
Oct 27, 2026
Merged

mindsers merged 2 commits into
developfrom
bugfix/flaky-git-timeout-test

Conversation

@mindsers

@mindsers mindsers commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Context

configfile runs git for almost everything, so before working it calls ensureGit (in src/process.ts), which runs git --version with a timeout. On timeout it kills git's whole process group, and it must not hang on an output pipe that a child of git still holds open.

tests/git.test.ts covers that with a fake git script: it starts perl -e 'use POSIX; setsid(); sleep 20' & (a child that leaves git's process group, so the group kill misses it), writes perl's pid to a file, then sleeps. The test expected ensureGit to give up after 0.3 s, and its finally block kills the escaped perl so nothing is left running.

Why

The develop build after #332 failed on this test (run 40461286040, ubuntu, Node 26) with kill ESRCH at tests/git.test.ts:178: the assertions passed, the cleanup threw.

On a slow runner the 300 ms timeout can fire before perl has run setsid(). Perl is then still in git's group, the group kill takes it down, and the cleanup's process.kill(pid, 'SIGKILL') targets a process that no longer exists. The same commit passed on its pull request, and the next develop build passed: it is a timing race, not a regression. The test dates from #289.

That race also hid a weaker test: when perl does not leave the group in time, nothing holds git's output open, and the test only checks again what "stops waiting for a git that does not answer" already checks. On a fast Mac, perl needs 150 to 200 ms to leave the group, so 300 ms left little margin.

Change

Two commits, both in that one test:

  1. The cleanup ignores a failed kill. The process is already gone, which is what the cleanup wants. This is the pattern tests/e2e.test.ts already uses for its process groups. Rethrowing anything other than ESRCH was not an option: Biome rejects a throw inside finally, and an error thrown by the cleanup would hide the test's own failure.
  2. The test makes sure it tests the escaped child.
    • The timeout goes from 300 ms to 1.5 s, which gives perl plenty of time to leave the group.
    • Perl creates a marker file right after setsid(). If the marker is missing when the timeout fires, the test is skipped with a note instead of passing.
    • The cleanup still kills by the pid that sh writes right after starting perl, so it never depends on the marker. Writing the pid from perl instead was rejected: the cleanup could read the file before perl writes it.
    • Perl now sleeps 5 s instead of 20, so a process that did escape the cleanup does not live long.
    • The time bound goes from 3 s to 4 s, still under vitest's 5 s test timeout.

Test-only change: no behaviour, documentation or compatibility impact. The test takes about 1.2 s longer.

Review order

  1. tests/git.test.ts, the test "stops waiting on time even when something git started keeps its output open": the fake git script, then the assertions and the skip, then the finally block.

Tests

  • pnpm typecheck and pnpm lint are clean.
  • pnpm vitest run: 810 tests pass. The test passed 10 times in a row, and no perl process was left afterwards.
  • Regression check: with ensureGit changed to wait for the output to close after the timeout (the finish call removed from the timer), the test fails ("Test timed out in 5000ms"). The change was reverted.
  • Skip check: with perl sleeping 3 s before setsid(), the test is skipped instead of passing. The change was reverted.
  • No manual test applies: nothing user-facing changed.

@mindsers
mindsers merged commit 7cba866 into develop Oct 27, 2026
21 of 22 checks passed
@mindsers
mindsers deleted the bugfix/flaky-git-timeout-test branch October 27, 2026 21:04
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.

1 participant