Skip to content

test: flaky LT_OnMountUnmountBalanced selftest — unmount count asserted before async OnUnmount flush completes #685

Closed

Description

Summary

Intermittent selftest failure: LT_OnMountUnmountBalanced (asserts LT_Unmounts_Exactly_30 + LT_NoLeak_MountsEqualUnmounts) in tests/Reactor.AppTests.Host/SelfTest/Fixtures/LifecycleTortureFixtures.cs. A generic lifecycle-torture fixture that mount/unmount-counts a TextBlock across rapid toggles.

Root cause (test-side race, not product code)

LT_Mounts_Exactly_30 passes (mounts == 30), but the final drive!(0) clear batch's OnUnmount callbacks have not all flushed when the unmount count is asserted → unmounts < 30 → assertion fails. The exactly-conserved unmount count is checked immediately after the clear batch rather than after a deterministic quiesce of the async OnUnmount dispatch.

Evidence

  • Observed on PR perf: cache per-render arrays/LINQ in DataGrid #669 CI, commit 9f640ba0, Selftests job run 28200113984: 1/1209 failed (only LT_OnMountUnmountBalanced).
  • gh run rerun 28200113984 --failed → Selftests PASSED (7m15s) on the same commit, zero code change → confirmed non-deterministic.
  • Not caused by perf: cache per-render arrays/LINQ in DataGrid #669: that branch touches only 3 DataGrid files (no AppTests.Host changes; only static readonly immutable arrays + pure methods). Every DataGrid fixture passed; the failing fixture doesn't use DataGrid. Fixture last modified by unrelated commit 222a299a.

Impact

False-red on the Selftests CI job that can hit any PR intermittently. Relevant right now because the perf-improvement fleet is about to go through an individual per-PR gh pr ready + CI + /perf GO cycle — a flake-induced red Selftests run during GO must not be mistaken for a real regression.

Suggested fix direction

Make the unmount-count assertion await a deterministic OnUnmount flush (drain/quiesce the dispatcher so all OnUnmount callbacks from the final drive!(0) clear batch have run) before asserting the conserved count — rather than asserting immediately after the clear batch. Alternatively add an explicit sync point that guarantees all OnUnmount callbacks completed.

Scope note

Not part of the /perf self-contained harness build fix (#677) — that is narrowly the StressPerf harness build, not selftest stability. Tracking this separately so it can be fixed independently / post-fleet.

Refs #669. Flagged by the Datagrid-allocs perf session.

Activity

  1. azchohfi commented on Jun 26, 2026

    @azchohfi
    CollaboratorAuthor

    Second independent occurrence — confirms this is cross-PR, not introduced by any one change.

  2. azchohfi commented on Jul 31, 2026

    @azchohfi
    CollaboratorAuthor

    Recurrence, one month on — now reproducing on the AOT leg specifically

    This closed issue's failure mode has reappeared. Details and evidence in the issue that references this one; summary here so subscribers see it.

    ecff5e5e / PR #770 fixed it by gating the asserts on await Harness.WaitFor(() => mounts == 30 && unmounts == 30), and that commit message correctly noted the outcome stays reachable when "WaitFor exhausts its passes". That is what is now happening.

    New information versus June: on an identical commit (run 30613122631), the JIT Selftests job passed while AOT Selftests failed. A genuine missed-unmount defect would fail both; a too-tight timing budget fails the slower runtime.

    Harness.WaitFor(Func<bool>, maxPasses = 25, perPassMs = 0) (Harness.cs:318) drains 25 render passes with zero wall-clock delay — a pass-count budget gating work that needs real time, which is why NativeAOT exhausts it where JIT does not. The harness already documents the escape hatch at Harness.cs:315.

    Suggested: reopen and fix at the call site by raising maxPasses and/or passing a non-zero perPassMs. Keep the asserts exact at == 30 — #770 was right to protect that, and widening the budget must not become relaxing the assertion.

  3. azchohfi commented on Jul 31, 2026

    @azchohfi
    CollaboratorAuthor

    Forward pointer, since this thread currently has no link to where the recurrence is being tracked: #994 is the live issue.

    That direction matters more than it looks. #994 references this issue, but nothing here referenced #994, so the link only worked if you arrived from the newer one. Anyone landing here — a closed issue whose most recent comment says "this came back" — had no route forward. This comment also puts a cross-reference event on #994, so the pair is now navigable from either end.

    One invariant worth stating explicitly, given the consolidation recommendation on #994: right now #685 is CLOSED and #994 is OPEN, so the bug has exactly one open tracker. Closing #994 as a duplicate without reopening this issue first would leave it with none — a real, reproducing, unfixed failure with no open tracker and a resolved issue as its only trace. That is strictly worse than the duplicate, and it is the same false-alibi shape that made misfiling it under the watchdog umbrella harmful in the first place. Either outcome is fine as long as one of the two is open when the dust settles.

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

    bugtest

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions