Repository navigation
fix: deflake //rs/tests/driver:unit_tests - #11880
Merged
Merged
Conversation
qemu_cmdline_names_pidfile_requires_the_pidfile_argument_pair read the children's /proc/<pid>/cmdline right after spawning them. But Command::spawn, via glibc's vfork-based posix_spawn, returns once the child's execve wakes the parent, which the kernel does before it switches the child to its new mm and records where the new argv is. Until then the cmdline shows the test's own argv (the address space is still shared) or nothing, so under CPU contention the child that names the pid-file did not match. Let each child echo a newline once sh runs and wait for it before reading its cmdline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused test-only handshake addresses the startup race without changing production behavior.
0 open findings
What changed in this PR
Stabilizes the driver's command-line matching unit test by waiting for child-shell readiness before inspecting /proc, addressing the startup race introduced with #11848.
Changes:
- Adds a piped stdout handshake to synchronize child startup.
- Leaves production behavior and test assertions unchanged.
| File | Description |
|---|---|
| rs/tests/driver/src/driver/local_backend.rs | Waits for each shell's newline before checking its command line. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dfinityianblenke
approved these changes
Oct 16, 2026
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.
Root cause
driver::local_backend::tests::qemu_cmdline_names_pidfile_requires_the_pidfile_argument_pair(added in #11848) spawns threesh -c 'read _' sh <args>children and then checks each child's/proc/<pid>/cmdline. Every failure is the same:Since the test landed on 2026-10-14 it failed in 3 of ~180 runs. Two were flaky runs on master (self-hosted runners). The
third was an RBE @ Namespace invocation on #11872 where all 3 attempts failed: it ran 599 of 698 tests on a cold cache,
with 200-330 actions running during the attempts. Its re-run, with at most 52 actions running, passed.
Command::spawncan return before the child's/proc/<pid>/cmdlineshows its new argv:Commandwith glibc'sposix_spawnp, which usesclone3(CLONE_VM | CLONE_VFORK). So the parentresumes as soon as the child's
execvewakes it.exec_mmap()→exec_mm_release()→complete_vfork_done()) before it switches the child toits new mm. If the child is preempted right there,
/proc/<pid>/cmdlinereads the still-shared address space, i.e.the test's own argv.
get_mm_cmdline()returns nothing untilcreate_elf_tables()has recorded where the new argv is.The test reads child 1's cmdline only after spawning the other two, which normally gives child 1 time to finish its exec.
Under CPU contention child 1 can still be in one of these windows, and then it doesn't match.
Reproduction
On an idle devenv (Linux 6.8, glibc 2.39), reading
/proc/<pid>/cmdlineright afterspawn()returned nothing in 1966of 2000 spawns. Copies of the real test binary, run concurrently and pinned to a few CPUs, fail with exactly the CI
assertion:
A standalone copy of the test that dumps the cmdline on failure showed the parent's argv and
commevery time (step 2).Fix
Each child now runs
echo; read _with stdout piped, and the test waits for that newline before it reads the child'scmdline.
shcan only print once its exec has completed, so its argv is in place by then.echois a builtin likeread, so the shell still doesn't fork. Ifshexits before it prints,read_exactfails at that point instead ofproducing the flake's assertion.
The production caller,
stop_qemu, is not affected. It checks the cmdline of the QEMU that wrote the pid-file, at least5 s after sending it SIGTERM.
This PR was created following the steps in
.claude/skills/fix-flaky-tests/SKILL.md.🤖 Generated with Claude Code