forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

stackflake.report.md72 lines, 4.2 KiBHistoryRawDownload
1# Lane stackflake: make `test_threads_get_the_stack_they_are_given` deterministic
2
3## Goal
4`stack_budget::tests::test_threads_get_the_stack_they_are_given` (ec-ac3 and ec-av1) failed
5intermittently. Make it deterministic without weakening what it guards.
6
7Base: branch `lane/stackflake` cut from `main` at `bfd5d20071588a36804053324662683bfd0b8d77`.
8
9## Root cause (reproduced)
10The explicit 1 MiB probe thread's stack mapping is found by parsing `/proc/self/task/<tid>/maps`.
11Linux merges adjacent anonymous mappings with the same protections, so the mapping that holds the
12thread's stack can grow past the stack's own size. The test had an upper bound
13`size <= 512 MiB` ("not a stack"), which a merged mapping can exceed.
14
15Reproduction, before the fix, locally (release, `cargo test --release -p ec-ac3 -p ec-av1 --lib
16stack_budget`, 50 iterations): **5 of 50 failed**. All 5 were the same assertion:
17
18```
19thread 'stack_budget::tests::test_threads_get_the_stack_they_are_given' panicked at crates/ec-av1/src/stack_budget.rs:954:9:
20the mapping holding an explicitly-1-MiB thread's frame is 537956352 bytes, which is not a stack -- the maps parse found the wrong region
21```
22(3 failures in ec-av1, 2 in ec-ac3; the ec-ac3 line is the same message at `stack_budget.rs:960`.)
23
24The lower bounds (`size >= 1 MiB` for the explicit thread, `size >= 2 MiB` for the default test
25thread) were never the failing ones. Merging only makes a region larger, so a floor stays valid.
26
27## Changes
28Both `crates/ec-ac3/src/stack_budget.rs` and `crates/ec-av1/src/stack_budget.rs`, same edit:
29- `stack_region` now returns `(lo, hi, writable)`. `writable` is the second character of the maps
30 permissions column. Merging joins only VMAs with matching protections, so a merged stack is
31 still writable, and that check does not depend on the merged size.
32- The `size <= 512 MiB` upper bound is replaced by `assert!(writable)` for the explicit thread and
33 for the default test thread. It still rules out a wrong region (a PROT_NONE or read-only mapping).
34- Lower bounds are unchanged: `size >= EXPLICIT` and `size >= 2 * 1024 * 1024`.
35- No `libc` dependency was added. Neither crate depends on `libc`, so `pthread_getattr_np` was not
36 an option under the lane's no-new-dependency rule.
37- No other crate has this test. `ec-opus` and `ec-vp9` have `stack_budget.rs` but not this test.
38
39## Verify
40Loop counts, each the test `stack_budget::tests::test_threads_get_the_stack_they_are_given`:
41
42| Setup | Before | After |
43|---|---|---|
44| Local, `cargo test --release -p ec-ac3 -p ec-av1 --lib stack_budget`, 50 runs | **5/50 failed** (513 MiB upper bound) | - |
45| Local, `-p ec-ac3`, 50 runs | - | 0/50 |
46| Local, `-p ec-av1`, 50 runs | - | 0/50 |
47| server (auto, host a), `-p ec-ac3`, 50 runs | 0/50 (not reproduced) | 0/50 |
48| server (auto, host a), `-p ec-av1`, 50 runs | - | 0/50 |
49| server host a/b/c, release full ec-ac3 lib binary, 50 runs each | 0/50 each (no failure) | - |
50| server host a, debug ec-ac3 binary, 4 concurrent copies x 50 | 0 failures in 200 | - |
51
52The server runs before the fix did not reproduce the flake. The failure only showed up locally. The
53pre-fix local loop is the reproduction.
54
55Commands and results after the fix:
56- `scripts/remote-run.sh stackflake --host auto -- cargo test --release -p ec-ac3 -p ec-av1 --lib stack_budget`:
57 `8 passed; 0 failed` for each crate.
58- `scripts/remote-run.sh stackflake --host auto -- cargo clippy -p ec-ac3 --all-targets -- -D warnings`:
59 `Finished`, clean.
60- `cargo clippy -p ec-av1 --all-targets` on the server: the only hit near `stack_budget.rs` is line 564
61 (`eprintln!("{:>8} {:>7} {}", ...)`), which is outside the changed lines and pre-existing. The
62 ec-av1 clippy failures belong to another lane.
63
64## Notes
65- The worktree already had an uncommitted change to `scripts/remote-run.sh` (3 job slots instead of 2)
66 when this lane started. It is not from this lane and is not in the commit.
67- `main` has advanced past the base sha above. The orchestrator merges.
68
69## Left
70- Nothing for this test. A bound-free check cannot catch a region that is writable but is not the
71 thread's stack, such as a heap mapping. The probe address lives on the thread's stack, so such a
72 mapping cannot contain it, and the test does not claim more than that.