Repository navigation
Make the doctor stop test catch a stop path that does not stop first - #2284
Merged
Merged
Conversation
The test "stopping a check that keeps starting processes in groups of their own leaves none of them" is meant to prove that the stop path stops a check's process group before it lists what the check started. It caught the stop path with no group SIGSTOP and no second listing in 22 of 200 ReleaseSafe runs, and in none under load. Only a process started between the first listing and the check's own stop escapes, a window of about a millisecond or two, and each child was a perl that took longer than that to leave its group. A hook in killTree, called once after the first listing, now holds the stop path until the forker has moved two more processes out of its group. It exists only in test builds: the variable is void and the call is compiled out otherwise. The forker is one perl process that records each child, moves it with setpgrp itself, and writes a byte to a pipe, so a byte says the process is out of the group. The hook waits on that pipe with poll(), at most five seconds, and returns at once when the stop has landed, as it has in the real stop path. The 200-process cap, the watchdog and the cleanup that never signals a reaped pid are unchanged.
On macOS the forker test failed without output. Perl's open of the pipe's write end by descriptor number failed with a bad descriptor, so the forker exited at once, no pid file appeared, and the test returned at its check that a process started, after the five second wait. std.process.spawn leaves a child on macOS only stdin, stdout and stderr, even for a descriptor that is not close-on-exec, so the forker cannot be handed an open one. The test now makes a named pipe in its temp folder before the forker starts and holds the read end open without blocking. The forker opens the pipe by its path. The hook, the product lines, the 200-process cap, the watchdog and the cleanup are as they were.
std.fmt.bufPrintSentinel is deprecated, and the check for deprecated Zig declarations in CI rejects it. The test now builds the pipe's path with std.mem.printSentinel. Each round also removes the named pipe's entry itself, on every path that leaves the round, beside the close of its read end, instead of leaving the entry to the cleanup of the test's folder.
If the test process dies after it starts the forker and before the forker opens the pipe, nothing holds the read end any more, and the forker's blocking open waits for a reader that never comes. The forker now opens the pipe with O_NONBLOCK, so an open with no reader fails with ENXIO and the forker ends. It clears the flag again right after, so its one-byte writes block as they did.
fazxes
marked this pull request as ready for review
November 25, 2026 05:59
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.
Summary
The test "stopping a check that keeps starting processes in groups of their own leaves none of them" is meant to prove that doctor's stop path stops a check's process group before it lists what the check started. #2012's mutant of the stop path, with no group SIGSTOP and no second listing (the 100 ms wait and
stopAllkept), passed it most of the time. This change makes the test fail on that mutant in every run, in ReleaseSafe and Debug, quiet and loaded, and the test passes on macOS. It changes no product behavior.Why the old test missed the mutant
Only a process started after the first listing and moved out of the check's group before the check itself stops can escape. That window is the listing: about 28 processes, 0.7 to 2.1 ms in ReleaseSafe and 1.3 to 2.4 ms in Debug. Each child was a new perl process, which took about 2 ms (median, quiet) to start and leave its group, and the forker started one about every 3 ms. Under load a perl start takes several times longer.
On 2 pinned CPUs, with 6 busy loops for "loaded", on unchanged
main:A forker that only started processes faster did not fix it. It caught every run when quiet, but only 69 of 100 in ReleaseSafe and 94 of 100 in Debug when loaded. A trace of 200 loaded rounds found no process started inside the window in 154 of them in ReleaseSafe and in 123 in Debug: the window is a few milliseconds, and a forker that sleeps between starts is often not on a CPU in it. Nothing outside the stop path can see that the listing is done.
What changes
killTreecallstest_after_listingonce, after the first listing. The variable is typed liketest_deferindelivery_test_controls.zig:if (builtin.is_test) ?*const fn (root: std.posix.pid_t) void else void. The call is underif (builtin.is_test), so other builds compile both out. Its doc line names the test. It is notpub, because only this file uses it. It adds no env var and no file control.holdUntilForkerMovesMore. The hook returns at once whenProcessProbe.stop_landedis set, whichstopTreessets withprocessIsStoppedon Linux and macOS, so the real stop path never waits in it. When the stop path left the forker running, the hook empties the named pipe, then waits withpoll(), at most 5 s, for two more bytes. The forker writes the second byte only after it started a process after the first byte and moved it out of its group, so that process is one the listing missed. R7.3 holds: it waits on a descriptor, not on a sleep.setpgrp($pid, $pid), and writes a byte to a named pipe, then pauses 1 ms. The pid file is written first, so a process outside the group is always one the test knows.O_NONBLOCK(sysopen) and clears the flag again right after, so its one-byte writes block as before. With the flag set, an open with no reader fails with ENXIO and the forker ends, where a blocking open would wait for a reader forever (see "If the test dies mid-round"). Each round closes the read end and removes the FIFO's entry on every path that leaves it, including a failedProcessProbe.create.Why the hook alone is not enough with the old forker
I built the hook with the old forker too (a shell loop that starts a perl per child, each moving itself and writing a byte; an inherited pipe, on Linux). It catches the mutant 100 of 100 in every config, but the real stop path waits in the hook. With a count printed when the hook starts to wait, over 100 loaded runs of 5 rounds:
Each wait ended at the 5 s bound (runs took up to 20.6 s). A forker whose children move themselves asynchronously cannot say when a process started after the listing is out of the group. The single forker has a small group of its own, so its stop lands in time.
The macOS failure and its fix
The first version failed
macOS arm64 unit testsin both macOS runs (45487664407 and 45487667022) with... leaves none of them' failed without output. I reproduced it on an arm64 Mac (macOS 27.2.1, Apple perl 5.34.1) with a diagnostic copy of the test, built in a sandbox and run only against the real stop code.expect(started_one)in round 0, notprobe.doneorstarted > 0. Perl'sopen(W, ">&=", 6)failed with "Bad file descriptor", so the forker exited at once, no pid file appeared in 5.8 s, and the test returned before it reached the other checks./bin/shand a plain/usr/bin/perl, started the same way asProcessProbe.spawnstarts a check, see only descriptors 0, 1 and 2, with the pipe open. The write end was not close-on-exec (F_GETFDreturned 0, as on Linux), and clearing the flag changed nothing. On Linux an extra descriptor is inherited, which is why only macOS failed. I read the 0.17.1 source:POSIX_SPAWN_CLOEXEC_DEFAULTis not set. I did not find which layer drops the descriptor, so the cause stated here is what I measured, not a reading of the source.pollreports nothing when a FIFO's writer closes, where Linux reportsPOLLHUP. The hook then waits for its 5 s bound, not for the end of the pipe, which matters only for a forker that dies before it writes two bytes.If the test dies mid-round
If the test process is killed after it starts the forker and before the forker opens the FIFO, nothing holds the read end any more. With a blocking open, that forker waits in
wait_for_partnerfor a reader that never comes. I killed the test (SIGKILL) as soon as its forker appeared, in a sandbox, and counted the forkers blocked in the FIFO open:One second after the kills, this commit still showed 41
sleep 30children of forkers that had already started. They are not blocked, and none was left at 41 s. A killed run still leaves its FIFO and pid files in its temp folder, like the pid files a killed run leaves onmain. This change does not remove them.Proof
All Linux runs are in sandboxes with Zig 0.17.1, on
origin/main(4ffe877160) plus this branch's diff, which is what CI merges. A catch is a failing run.m2012caughtulimit -u,timeout -k 5 60andFX_SOUND=0: 20 of 20 pass, each under 1 s, and 0 processes of the test left after any run. The same on each of the last three commits.Build & Testjob's steps, asorigin/main'sci.ymllists them, run in a sandbox on that tree: formatting, PGSO, the public-surface and four boundary scripts, the five model checks and the four drivers that walk them, CLI shape, the CI and zig-skill unittests,zig build, and the direct-write audit (classified=113 unclassified=0) all exit 0. All six CI build surfaces exit 0.check_deprecated.py src build.zig benchmarks testsexits 0 (0 removed, 0 deprecated).zig build test -Doptimize=ReleaseSafe --summary allon that tree: 13056 of 13100 passed, 12 failed, 8 distinct names. They are the same names as in the cleanorigin/mainrun on the earlier tipf473287ddb(13039 of 13083, 12 failed): file-permission tests that fail as root, and one capture-store timing test. Two earlier full runs on an older base showed up to two more failing names and one crash (the terminal client,auto_upgrade, and a second capture-store timing test). They did not show again in reruns, so I take them for flakes, but I did not isolate their cause.fx, the same with-Dcpu=baseline, both Wasm builds and the four N-API targets were byte-identical to the ones built fromorigin/main'sdoctor_probes.zig, in the same sandbox and clone (8 of 8). This commit changes only the perl script text and a comment inside the test, so no product line changes. I did not rerun that check on it.Not verified
macOS arm64 unit testsjob takes about 30 minutes.stopTrees, asstop_landedis documented to.