test(hle): two tests share process-wide state, so a full-suite run is red about one time in three #620
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS#620
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AnastasisKon on GitHub · 2026-11-28 14:13 UTC · original
What went wrong
cargo test --target x86_64-apple-darwin -p victory-hle --libfailsintermittently — roughly one run in three, on a clean
main— because teststhat share process-wide state run in parallel with each other. A green run
is therefore not yet a trustworthy signal, and a red one hides real regressions
(it cost two false reds today while landing #10–#14).
Two symptoms, measured on
mainat2200a393(M3 Pro, macOS 27.3), with--librun ten times each:modules::dsp::tests::dump_captures_the_titles_ir_blocks_and_outputstd::fs::read(dir.join("stream0_ir.f32"))— file missinghost_posix::winsock::tests::final_cleanup_invalidates_sockets_and_releases_their_portswinsock.rs:1607—bindof a fixed porthost_posix::winsock::tests::off_machine_traffic_is_refusedwinsock.rs:1788— "not started again"Both pass when run alone, which is why they were not spotted earlier.
Why
dsp. The test setsVICTORY_DUMP_DSPwithstd::env::set_var— unsafe inedition 2024 precisely because it is process-wide — comments "no other test
reads VICTORY_DUMP_DSP", and relies on that. But the module reads it on
every activation, and any other test that activates a stream while the
variable is set is captured too. Stream numbers come from a process-wide
counter, so a concurrent activation moves this test's dump from
stream0_*tostream1_*and the file it reads is not there.winsock.WSAStartup/WSACleanupkeep one process-wide reference count,and
final_cleanup_...asserts on it — "not started again" atwinsock.rs:1788is false whenever another test has started Winsock meanwhile.The same test binds a fixed port, so it fails when a concurrent test, or a
previous run's lingering socket, holds that port.
Suggested fix
A test-only lock, the same way the DSP/POSIX tests already serialize what they
cannot share:
static LOCK: Mutex<()>inmodules::dsp's tests, taken by the dump testand by every test that activates a stream (or, better, point the dump at a
directory per activation so numbering cannot cross);
host_posix::winsock's tests, taken by every test that asserts on theWSAStartupreference count, with the fixed port replaced by an ephemeralone (
bindport 0 and read the port back withgetsockname).Two of the suite's flakes were already fixed separately: which waiter a single
WakeByAddressSinglereaches (#12,b90ad5d4), and an address that is onlyusually in the same stripe (#14,
2200a393).Mac, macOS version and commit
M3 Pro, 36 GB, macOS 27.3,
x86_64-apple-darwin(Rosetta), commit2200a393.Output or log
@AnastasisKon on GitHub · 2026-11-28 14:26 UTC · original
Two of the three are fixed, and one of my diagnoses was wrong — correction below.
dsp::dump_captures_...— fixed in #16 (17f6d895). The cause is asguessed, and worse than guessed:
VICTORY_DUMP_DSPis process-wide and so isDUMP_ID, the counter numbering each stream's capture. The other test in themodule that activates a stream (
convolution_stream_as_the_title_drives_it)could therefore start a stream inside the dump test's capture, take number 0,
and leave the dump test reading that stream's capture. The file it found had the
right length and its own stream's zeros, which is why it read as a capture bug:
The two now take turns through one lock. Nothing else in the crate activates a
stream — every other
XDspConnectWithMaximumStreamLimit/XDspActivatecall isin that module's tests.
sync::wait_on_address_...— the flake in the report was fixed in #12, and myfollow-up in #14 was still wrong; that is fixed in #15 (
4481ca91). #14searched forward from the first address for one in the same stripe, but stripes
repeat per page (
((addr >> 2) ^ (addr >> 12)) & 31), so the search onlysucceeded while the allocation sat far enough from the end of its page: it
panicked on its own
expecton 1 run in 15. The neighbour is now taken onwhichever side of the address still has room in its page.
winsock— my explanation was wrong, so the fix needs a different one. Bothtests already take the module's
serial()guard (winsock.rs:1568), so theWSAStartupreference count is not what breaks. What is left isfinal_cleanup_invalidates_sockets_and_releases_their_portsasserting that theephemeral port the old socket held is free again:
portcame frombind_(old, loopback_addr(0), 16)— the OS chose it — andbetween
WSACleanupand the rebind any otherbind_(.., 0)in the process (or alingering socket from an earlier run) can be handed the same number, so the
rebind fails for a reason that is not a leak. Suggested fix: choose the port
rather than let the OS choose it — bind once to prove it is free, release it, and
rebind the same number — and keep the existing "the old socket is no longer
usable" assertions unchanged.
I have not touched the winsock tests. Measured on
mainat17f6d895, 8 runs ofthe whole suite: 0 failures, i.e. the winsock pair is now the only residual and it
did not appear in those runs.
@AnastasisKon on GitHub · 2026-11-28 14:36 UTC · original
All three are fixed now, and the third cause was not what I first wrote.
The real cause of the winsock pair: the Winsock tests already take a turn for
the process-wide startup count, but
modules::net'sonly_loopback_is_reachabledrives the same functions by name —
host!("ws2_32.dll", "socket"),connect,WSAConnectByNameA,WSAIoctl,closesocket— and did not. On this host thosereach the native Winsock, so that test could start the stack inside
off_machine_traffic_is_refused's "not started again" assertion, or take anephemeral port inside
final_cleanup_invalidates_sockets_and_releases_their_ports'srebind of one it had just released. That is why the module alone never failed:
host_posix::winsockon its own was 0 failures in 20 runs, the suite was not.The turn now lives in
host_posixaswinsock_turn(), taken by the Winsock tests(through their existing
serial()) and by thatnettest, compiled only wherethe native host is. Fixed in #17 (
d7c58a90).Summary of the three, in the order they were fixed:
sync::wait_on_address_...dsp::dump_captures_...winsock::final_cleanup_...,winsock::off_machine_traffic_...Measured after all of them, on
main: the wholevictory-hlesuite ran 32times in a row with no failure (20 + 12), against roughly one in three when
this issue was filed. I am closing it.