Repository navigation
fix: make four intermittently failing Rust tests deterministic - #106
Open
teo-goulois wants to merge 5 commits into
Open
teo-goulois wants to merge 5 commits into
teo-goulois wants to merge 5 commits into
Conversation
An epoch is base64url, so one in 64 starts with '-'. clap then took '--have -1aB:3' for an unknown option, and 'localify inventory --have' failed. This is what made the_daemon_reports_each_state_and_revision_of_a_service fail now and then at tests/inventory.rs:309.
The DNS server bound its sockets in a task of its own, while the management socket already answered. When another program took the DNS port in between, the daemon answered status and inventory requests and then exited. The sockets are now bound first, so such a start fails before anything sees the daemon up, with a message naming the port.
The loop decides whether to scan before it reads the Ctrl+C count. A press that came in between was handled with the last scan, which could predate a worker the service had just started. That worker got no SIGINT, was orphaned when the launcher exited, and was never stopped. The interrupt now scans the tree itself.
An executor records its exit, then releases the service's lock. A launch in between found the lock held and refused with "'web' is already running", though the run had ended. It now waits for the lock while the record (or the launch record) holds the run's exit and its executor still runs, up to the same 10 s as after a stop. This is what made a_lost_acknowledgement_is_reported_exactly time out waiting for B.
…once On macOS a flock belongs to the open file description, which a child another test forks keeps until it execs: right after a drop, the lock may still be held for a moment. the_finalize_lock_is_exclusive_and_never_recreates_a_folder failed this way on main; the_lock_admits_one_executor_at_a_time relies on the same thing. Both now wait for the release. a_stop_whose_executor_dies_goes_on_only_under_the_lock waited 5 s for a SIGTERM sent after a journal write; under heavy disk load that write alone took longer. Its hang guard is now 30 s, as for the other waits of that file.
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.
Four tests failed now and then on CI (around #100 and #101), then passed on rerun. Each one comes from a real race. Three of the races are in production code.
Root causes
tests/inventory.rs—the_daemon_reports_each_state_and_revision_of_a_service(Ubuntu,inventory.rs:309,None.unwrap())The inventory epoch is 16 random bytes encoded as base64url, so about one epoch in 64 starts with
-. clap then readlocalify inventory --have -1aB…:3as an unknown option, and the command failed witherror: unexpected argument '-1' found. I caught that exact output with the test instrumented. The same failure was already onmainon Nov 9 (run 42693843108). Fix:allow_hyphen_valueson--have, plus a parse test.While looking into it I also found and fixed a second race in the daemon. The DNS server bound its sockets in a task of its own while the management socket was already answering. If another program took the DNS port in between, the daemon answered
status/inventoryand then exited. The DNS sockets are now bound before anything is served, so such a start fails before anyone sees the daemon up, and the error names the port.tests/remote_controls.rs—a_lost_acknowledgement_is_reported_exactly(Ubuntu, "timed out waiting for B registered")An executor records its exit (launch record, then service record), then releases the service's lock. A launch arriving in between found the lock held and gave up with
'web' is already running (PID …), though the run had already ended. B never registered, and the test waited 30 s. Fix (admit): while the record or the launch record holds the run's exit and its executor still runs, the new launch waits for the lock instead of refusing. It waits up to the existingRELEASE_TIMEOUTof 10 s, the same wait as after a stop. Unit test added. User-visible:localify dev(or a remote/app start) issued right after a run ended no longer fails with "already running".src/cli/service_supervisor.rs—a_worker_that_ignores_ctrl_c_is_stopped_after_its_launcher_exits(macOS, "the worker survived its launcher")supervisedecides whether to scan before it reads the Ctrl+C count. A press landing in between was handled with the previous scan, which could be from before the service forked its worker. Only the launcher got the SIGINT. The launcher exited, the worker was orphaned outside the tracked tree, and it was never stopped. Fix: the first interrupt rescans the tree itself. User-visible: a child that a service spawns right before Ctrl+C is now stopped with it instead of being left running.src/infrastructure/runs/output.rs—the_finalize_lock_is_exclusive_and_never_recreates_a_folder(macOS, onmainrun 45164540766)On macOS a
flockbelongs to the open file description. A child forked by another test in the same process keeps that description until it callsexec, so right afterdrop(held)the lock can still be held for a moment. I confirmed this with a fork/flock script. The test, andthe_lock_admits_one_executor_at_a_time, which relies on the same thing, now wait for the release instead of asserting it at once. Production callers already wait (acquire_within,CLEANUP_WAIT).Reproduction, before → after
Natural failure rates are low: the tests passed 0/48 at rest on this Mac. So I reproduced each race deterministically by injecting a delay into the window, then ran the fixed code under load. All injected delays are removed.
'web' is already running)"Under load" here means 4 copies in parallel on an 8-core Mac whose load average ran between 60 and 400 from unrelated Xcode/simulator builds.
Also touched
tests/runs.rs—a_stop_whose_executor_dies_goes_on_only_under_the_lockfailed once locally at load ≈370: the SIGTERM comes after a journal write, which a saturated disk delayed past the 5 s guard. The guard is now 30 s, like the other waits in that file. It only bounds a hang; the timing assertions are unchanged.Other flaky tests seen, not fixed
daemon::remote::tests::viewing::{a_large_follow_stays_inside_the_relays_budgets, a_viewer_flooding_gets_and_reads_keeps_the_target_bounded, a_viewer_gets_every_page_then_unchanged},daemon::remote::tests::cli::following_goes_on_with_the_run_that_replaces_a_restarted_oneanddaemon::public_tunnel::tests::shutdown_kills_cloudflaredfailed in 7 of 15 full runs, mostly withnot_responding("It stopped answering") from the fake relay. They have not failed on CI. The cause is not clear or small enough to fix here.tests/app_bridge.rsa_launch_handed_to_the_app_runs_in_a_tab_and_its_restart_takes_that_tab_over(twice),desktop::app_bridge::tests::connections_past_the_limit_are_closed_and_the_bridge_goes_on,tests/run_pty.rsa_killed_executor_s_run_is_ended_and_finalized_complete_by_the_app,daemon::remote::tests::reconnecting_does_not_reset_the_pairing_limit. Not investigated here.cargo fmt --check,cargo clippy --locked -- -D warningsandcargo testpass locally on Rust 1.99.1; the toolchain pin is unchanged.