Skip to content

Flaky: tests that need process-wide isolation race since #978 merged them into shared binaries #1133

Closed

Description

@zackees

Master push run 38979468586 (2026-10-16 23:04 UTC, the merge of #1128) failed in Build 🧱 / Rust Tests 🦀 (macos-26):

---- threading_allocs::init_destroy_counts_one_bzalloc_per_live_handle stdout ----
panicked at rust/obs-util/tests/threading/threading_allocs.rs:32:5:
assertion `left == right` failed
  left: 6
 right: 5

#1128 didn't cause this; the previous 14 master pushes passed. The cause is #978 (a263104).

Cause. The test asserts absolute deltas of bnum_allocs(), a process-wide counter. Its header says why it has to run alone:

This lives in its own test binary with a single test on purpose: bnum_allocs is a process-global counter, so asserting absolute deltas races with any concurrent allocation — including a second test in the same binary.

#978 (category binaries, #968) moved it into rust/obs-util/tests/threading/main.rs with task, task_stress, threading_stress and others, 39 tests in all, which run in parallel by default. Any of them that allocates through bmem between the test's base read and its check moves the counter.

Fix options (the binary cap ci/test_binary_cap.py stops it going back to its own tests/*.rs: obs-util is already at 8 of 8):

  1. Run the body in a child process. The test re-executes std::env::current_exe() with --exact threading_allocs::... --test-threads=1 and an env var, and the child does the measurement. This keeps the binary count unchanged and makes the test deterministic.
  2. Exempt this one test from the cap with a documented allow-list entry in ci/test_binary_cap.py and restore tests/threading_allocs.rs.
  3. Check the same thing without the global counter, for example by counting allocations in the oracle stand-ins on the calling thread only.

Also check the other tests that #978 moved for header comments about running alone, or for reads of bnum_allocs.

Activity

  1. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    The same race can hit rust/obs-util/tests/memory/bmem_parity.rs. Its matches_c_oracle proptest reads rs::bnum_allocs() before and after each op, and #978 put it in the memory binary next to bmem.rs, whose tests allocate through bmem in parallel. Whatever fix is chosen should cover both.

  2. changed the title [-]Flaky: threading_allocs races other tests since #978 merged it into the shared threading binary[/-] [+]Flaky: tests that need process-wide isolation race since #978 merged them into shared binaries[/+] on Oct 17, 2026
  3. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    A third case, in the platform binary. Fast Gate on #1094 (run 38996720085, 2026-10-17 ~03:05 UTC) failed with:

    ---- pipe_parity::process::dead_pipe_write_survives_concurrent_spawns ----
    panicked at rust/obs-util/tests/platform/pipe_parity.rs:459:13
      left:  b"sh: 0: getcwd() failed: No such file or directory\nclosed\n"
      right: b"closed\n"
    

    platform_nix_parity::getcwd_matches_and_chdir_roundtrips changes the process working directory into a scratch("cwd") directory and removes it afterwards. It only holds its own cwd_lock(). pipe_parity spawns sh children under a different lock (SPAWN). Since #978 put both files in one binary, a child can start with the cwd set to the scratch directory just as the directory is removed, and sh then prints that getcwd() warning to the stderr the test compares.

    #1094 doesn't touch either file; I re-ran its failed jobs. The fix belongs with the other two: a test that changes process-wide state (cwd, the bnum_allocs counter) can't share a parallel test binary with tests that depend on that state. Options: run it in a child process, share one lock across both modules (the cwd test and every spawn), or, for this one, do the chdir round trip in a forked child so the parent's cwd never moves.

  4. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    Correction to the third case above. The leaked-fd failure on #1094's next run (1 of 3000 writes reached a dead child through a leaked fd) came from my own maintainer push. I had moved #1094's forking platform_oracle tests into the platform binary next to pipe_parity. That one is now fixed on #1094 by moving them to profiler. The getcwd() failed race between platform_nix_parity's chdir test and pipe_parity's spawns is separate and still open; it's on master already. General rule for whoever fixes this issue: a test that forks without exec, changes the cwd, or reads bnum_allocs must not share a parallel test binary with tests that depend on that state.

  5. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    Claiming: option 1 (child process). A shared test helper re-executes the test binary with --exact <test> --test-threads=1 and an env var; the child does the bnum_allocs measurement, the parent asserts the child passed. Applied to threading_allocs::init_destroy_counts_one_bzalloc_per_live_handle and bmem_parity's counter checks. RED is deterministic: a background thread allocating through bmem while the in-process measurement runs; GREEN passes with that thread still running because the measuring process is a separate one.

  6. added
    claimed
    on Oct 17, 2026
  7. added 3 commits that reference this issue on Oct 17, 2026
    bc78d71
    3ff7bd7
    622236d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions