Tests: the watch tests' random failures came from a view another test freed mid-change #446

Closed
github-bot wants to merge 1 commit from github-bot/gh-446 into a-publier AGit
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 02:17 UTC · original
MamaLeVrai:watch-flakes → a-publier · +39 −3 · 1 files · 1 commits · closed without merging

What

The watch::tests::* tests fail at random on this card when the lib suite runs in parallel. A different test fails each time: a_block_just_written_rests, a_write_opens_the_view_it_goes_through, bits_go_at_every_view, what_the_kernel_writes_through_is_not_guarded_for_another_view, written_pages_are_reported_to_every_asker, ... Other testers see the same, and it gets in the way of every PR's report. Sometimes what_the_title_puts_in_beside_a_guard_is_told even hangs.

Cause (test-only): watch::many_askers_tests::writes_to_views_are_not_lost has a helper thread that maps and unmaps a one-page view 300 times. Each time it frees the address while its mapping change is still open: title_memory_remapping(), then title_memory_unmapping(one, PAGE) records the block in the global Guards::changing, then UnmapViewOfFile, and only then is the change dropped. In that gap Windows hands the freed address to a watch::tests test running at the same time. Its new block lies inside changing, so guard() leaves it alone (Guards::left_alone) and never protects it. The block is then always reported as written, and a put loop that waits for the guard spins forever.

Fix (test-only, +39/-3): the helper keeps one page reserved as a placeholder of its own. It maps the view there with MapViewOfFile3(MEM_REPLACE_PLACEHOLDER) and unmaps it with UnmapViewOfFile2(MEM_PRESERVE_PLACEHOLDER), as no_mapping_is_lost_between_askers in the same module already does. The address can no longer go to another test.

Production code is not affected. The runtime alone maps title memory, under its mapping lock. Even an address reused during a change would only be reported as written and copied again; no write is lost.

Numbers (RX 6950 XT, Windows 11 build 26300, release)

runs runs with a watch:: failure
a-publier 4eb6cfd, whole lib binary, 8 threads 60 + 78 34 + 39
this PR, whole lib binary, 8 threads 60 0
a-publier, watch:: only, 8 threads 20 11
this PR, watch:: only, 8 threads 20 + 30 0

Evidence for the cause: with --test-threads=1 there are 0 failures in 15 runs; watch:: without many_askers_tests has 0 in 20; watch::tests with many_askers_tests has 11 in 20. A temporary check (not committed) showed that each failing test had its block inside another test's "changing" range.

Not fixed here

The remaining rare failures after the fix are other tests: descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes (also on base, 3 in 78) and host::refresh_tests::unchanged_ranges_are_known (seen once after the fix, and once on another PR's branch).

AI-assisted (Claude Code); no game data.

🤖 Generated with Claude Code

**@⁠MamaLeVrai** on GitHub · 2026-11-27 02:17 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/446) `MamaLeVrai:watch-flakes` → `a-publier` · +39 −3 · 1 files · 1 commits · closed without merging ## What The `watch::tests::*` tests fail at random on this card when the lib suite runs in parallel. A different test fails each time: `a_block_just_written_rests`, `a_write_opens_the_view_it_goes_through`, `bits_go_at_every_view`, `what_the_kernel_writes_through_is_not_guarded_for_another_view`, `written_pages_are_reported_to_every_asker`, ... Other testers see the same, and it gets in the way of every PR's report. Sometimes `what_the_title_puts_in_beside_a_guard_is_told` even hangs. **Cause (test-only):** `watch::many_askers_tests::writes_to_views_are_not_lost` has a helper thread that maps and unmaps a one-page view 300 times. Each time it frees the address while its mapping change is still open: `title_memory_remapping()`, then `title_memory_unmapping(one, PAGE)` records the block in the global `Guards::changing`, then `UnmapViewOfFile`, and only then is the change dropped. In that gap Windows hands the freed address to a `watch::tests` test running at the same time. Its new block lies inside `changing`, so `guard()` leaves it alone (`Guards::left_alone`) and never protects it. The block is then always reported as written, and a `put` loop that waits for the guard spins forever. **Fix (test-only, +39/-3):** the helper keeps one page reserved as a placeholder of its own. It maps the view there with `MapViewOfFile3(MEM_REPLACE_PLACEHOLDER)` and unmaps it with `UnmapViewOfFile2(MEM_PRESERVE_PLACEHOLDER)`, as `no_mapping_is_lost_between_askers` in the same module already does. The address can no longer go to another test. **Production code is not affected.** The runtime alone maps title memory, under its mapping lock. Even an address reused during a change would only be reported as written and copied again; no write is lost. ## Numbers (RX 6950 XT, Windows 11 build 26300, release) | | runs | runs with a `watch::` failure | |---|---|---| | `a-publier` `4eb6cfd`, whole lib binary, 8 threads | 60 + 78 | 34 + 39 | | this PR, whole lib binary, 8 threads | 60 | 0 | | `a-publier`, `watch::` only, 8 threads | 20 | 11 | | this PR, `watch::` only, 8 threads | 20 + 30 | 0 | Evidence for the cause: with `--test-threads=1` there are 0 failures in 15 runs; `watch::` without `many_askers_tests` has 0 in 20; `watch::tests` with `many_askers_tests` has 11 in 20. A temporary check (not committed) showed that each failing test had its block inside another test's "changing" range. ## Not fixed here The remaining rare failures after the fix are other tests: `descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes` (also on base, 3 in 78) and `host::refresh_tests::unchanged_ranges_are_known` (seen once after the fix, and once on another PR's branch). AI-assisted (Claude Code); no game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
writes_to_views_are_not_lost unmapped its extra view inside a change of
mapping (title_memory_remapping + title_memory_unmapping, which notes the
block in Guards::changing) and only ended the change after UnmapViewOfFile.
In that window Windows hands the freed address to a watch::tests test
running in parallel; its fresh block is then left_alone() by guard(), never
made read-only, and the test sees it written / writable when it should not
(a_block_just_written_rests, a_write_opens_the_view_it_goes_through, ...),
or loops forever in what_the_title_puts_in_beside_a_guard_is_told.

The view now comes and goes in a one-page placeholder the thread reserves
and keeps (MapViewOfFile3 / UnmapViewOfFile2 with MEM_PRESERVE_PLACEHOLDER),
as no_mapping_is_lost_between_askers already does, so the address is never
another test's. Test-only; the runtime is the sole mapper of title memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:29:54 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-27 02:18 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-27 02:18 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/446#pullrequestreview-6082631144) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 03:20 UTC · original

#450 fixes the same thing and covers one more test that freed its view during a change, so it should be taken instead of this one. I'm leaving this open only until that is settled, because #462 sits on it.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 03:20 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/446#issuecomment-7208905343) #450 fixes the same thing and covers one more test that freed its view during a change, so it should be taken instead of this one. I'm leaving this open only until that is settled, because #462 sits on it. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠lvndrpup on GitHub · 2026-11-27 03:31 UTC · original · reviewed

Tested on an RTX 3060 Ti 8 GB, Ryzen 5 5600X, 32 GB, Windows 11 build 26300, Rust 1.98.1, debug, 2f18312 merged with #382 (3ed1953):

alternating runs failed runs
watch::, a-publier + #382, without this PR's change 2 of 40
watch::, the same with this PR's change (and #450's) 0 of 40
watch:: host::refresh_tests, a-publier + #446 + #382 0 of 30

I found the same cause and opened #450 eight minutes after you. Yours came first, so I have cut #450 down to the one thing this leaves. tests::nothing_is_guarded_between_our_forgetting_it_and_its_unmapping also unmaps its view before drop(changing), and #450 now only moves that unmap after the drop. The two PRs touch different tests and merge in either order.

One nit: hole is not released after the 300 rounds, so its page stays reserved for the rest of the test process. That's harmless, but a VirtualFree(hole as *mut _, 0, MEM_RELEASE) after the loop would tidy it.

**@⁠lvndrpup** on GitHub · 2026-11-27 03:31 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/446#pullrequestreview-6083088190) · **reviewed** Tested on an RTX 3060 Ti 8 GB, Ryzen 5 5600X, 32 GB, Windows 11 build 26300, Rust 1.98.1, debug, `2f18312` merged with #382 (`3ed1953`): | alternating runs | failed runs | |---|---| | `watch::`, `a-publier` + #382, without this PR's change | 2 of 40 | | `watch::`, the same with this PR's change (and #450's) | 0 of 40 | | `watch:: host::refresh_tests`, `a-publier` + #446 + #382 | 0 of 30 | I found the same cause and opened #450 eight minutes after you. Yours came first, so I have cut #450 down to the one thing this leaves. `tests::nothing_is_guarded_between_our_forgetting_it_and_its_unmapping` also unmaps its view before `drop(changing)`, and #450 now only moves that unmap after the drop. The two PRs touch different tests and merge in either order. One nit: `hole` is not released after the 300 rounds, so its page stays reserved for the rest of the test process. That's harmless, but a `VirtualFree(hole as *mut _, 0, MEM_RELEASE)` after the loop would tidy it.
Author
Owner

@⁠lvndrpup on GitHub · 2026-11-27 04:35 UTC · original

Update: my review above is out of date. Following MamaLeVrai's comment, #450 carries the full fix again (391d2a9, both tests), so this PR can be closed in its favour.

**@⁠lvndrpup** on GitHub · 2026-11-27 04:35 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/446#issuecomment-7209924748) Update: my review above is out of date. Following MamaLeVrai's comment, #450 carries the full fix again (`391d2a9`, both tests), so this PR can be closed in its favour.
github-bot closed this pull request 2026-11-27 05:14:54 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 05:11 UTC · original

Closing in favor of #450, which carries the full fix (both tests). #462 is being rebased so it no longer sits on this commit.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 05:11 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/446#issuecomment-7210432546) Closing in favor of #450, which carries the full fix (both tests). #462 is being rebased so it no longer sits on this commit. AI-assisted (Claude Code); no game data.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.