Skip to content

#738 Stop the race harness calling slowness a hang, and leaking a locked database that poisons the next run - #746

Merged
nockawa merged 1 commit into
mainfrom
olc-738-harness
Aug 10, 2026
Merged

nockawa merged 1 commit into
mainfrom
olc-738-harness

Conversation

@nockawa

@nockawa nockawa commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Repairs the OLC race-stress harness, which had been the primary evidence source for #297 / #679 / #738 / #739 while carrying four defects that produce the same signal as a tree bug. Addresses #738; deliberately not auto-closed — the tree-side defect it uncovered is still open.

Independent of #745; no file overlap, either order merges.

What was wrong with the instrument

1. "HANG" was a ten-second wall clock, not a detected deadlock. RunScenarioLoop records it when iterTask.Wait(IterationDeadline) expires — default 10 s, against a scenario body running under ProcessorCount/2 CPU-saturating noise threads plus four other scenario loops. A bounded-but-glacial iteration trips it identically to a stuck one, and the pessimistic paths allow MaxPessimisticRestarts = 10,000, measured at 2 m 34 s single-threaded in #740.

Reading that label as evidence of a lock cycle is what sent five hypotheses in #738 to be refuted one at a time — each looking for something that was never there. Relabelled DEADLINE, with the distinction stated at the site and a pointer to capture stacks rather than infer.

2. The deadline path leaked the database, by design. Its own comment: "Skip cleanup; let the orphan workers churn... Memory leak across HANG iters is bounded by the stress duration." It is not bounded by the stress duration — a testhost.exe from a completed run stayed alive holding the test DLL and had to be killed by PID before a rebuild could copy over it.

3. So one deadline poisoned every later run, deterministically. _scenarioId restarts at 0 in each test host and the name was olcrs_{id:x} — unique within a process, identical across them. A leaked lock therefore sat exactly where the next run would ask for it; EnsureFileDeleted cannot remove a file another process holds, and LoadFile throws.

Measured: three consecutive isolated runs failed identically at olcrs_2397, and 33,088 leaked olcrs_*.typhon directories had accumulated under the test bin. Now olcrs_{ProcessId:x}_{id:x} — the leak becomes self-contained instead of contagious.

4. The fixture was never [NonParallelizable]. The assembly runs Parallelizable(ParallelScope.Fixtures) at LevelOfParallelism(4). OlcBTreeStressTests carries the attribute; this one did not — so a harness already spawning five scenario tasks plus ~16 noise threads ran as one of four concurrent heavy fixtures. That configuration took the test host down, with ChaosStressTests.UltimateStress_AllSubsystems, SubscriptionStressTests.MultiClient_50Clients_SharedView_AllReceiveDeltas and WalCrashSweepTests.Exhaustive_PageAxis_SingleTxSpawn_N33 in flight alongside it.

What a working instrument then showed

Six runs, 68,123 iterations: no hangs, no crashes, no missing keys in any scenario.

scenario iterations failures
Add_Splits 6,001 6
Add_Disjoint 13,129 2
Remove_Disjoint 16,931 3
Remove_Merges 15,977 1
Remove_Mixed 16,085 0

Read no rate published before this change as a property of the tree.

#738 is not a deadlock

The experiment that settles it — same build, same 60 s of stress, only the iteration deadline changes. If the iteration is stuck, no budget helps; if it is merely slow, a bigger budget lets it finish.

iteration deadline iterations DEADLINE records
10 s 11,694 1
10 s 19,972 2
300 s 19,445 0

At 300 s the deadlines vanish and are replaced by both Add_* scenarios reaching the bound and throwing:

InvalidOperationException: B+Tree insert made no progress in 10000 pessimistic retries.
  at BTree`2.AddOrUpdateCorePessimistic(InsertArguments&)   BTree.Insert.cs:620

Same event, two labels. It is the same defect class as #740 and a different instance — the Add_* scenarios never call Remove, and the #740 fix was already in that build. Left open: which restart in the pessimistic insert fails to make progress. The instrumentation shape that worked on the Remove side is per-exit counters, so a burn names its exit instead of leaving it to inference.

#739 reproduces, and it is not garbage

Remove_Disjoint (not Remove_Merges), in RemoveLeaf's merge-from-right branch:

GetChunkLocation: Computed page index 19027 >= segment length 50. ChunkId=589824
  at NodeWrapper.SetPrevious   BTree.NodeWrapper.cs:92
  at NodeWrapper.RemoveLeaf    BTree.NodeWrapper.cs:559

Identical ChunkId and page index across two independent runs. 589824 is 0x90000 — low 16 bits zero, the shape of a packed field read as a chunk id, not of corrupted memory.

Scope

Test-fixture changes only; no engine code. Build verified standalone. Companion doc correction in typhon-claude.

…ked database that poisons the next run

OlcBTreeRaceStressTests recorded "HANG" when iterTask.Wait(IterationDeadline) expired. That is a ten-second wall clock, not a detected deadlock, and a bounded-but-glacial iteration trips it identically to a stuck one: the pessimistic paths allow MaxPessimisticRestarts of 10,000, measured at 2m34s single-threaded in #740, against a scenario body running under ProcessorCount/2 CPU-saturating noise threads. Reading that label as evidence of a lock cycle is what sent five hypotheses in #738 to be refuted one at a time, each looking for something that was never there. It is DEADLINE now, and the comment at the site says what it does and does not establish, and that the answer is in the stacks rather than in this counter.

The deadline path deliberately skipped cleanup and leaked the ManagedPagedMMF with its file still open, reasoning that orphan workers may be alive and that the leak is bounded by the stress duration. It is not bounded by the stress duration. A testhost.exe from a completed run stayed alive holding the test DLL, and had to be killed by pid before a rebuild could copy over it.

Because _scenarioId restarts at 0 in every test host, olcrs_{id:x} was unique within a process and identical across processes, so a leaked lock sat exactly where the next run would ask for it. EnsureFileDeleted cannot remove a file another process holds, and LoadFile throws. Three consecutive isolated runs failed identically at olcrs_2397, and 33,088 leaked database directories had accumulated under the test bin. Including the process id makes the leak self-contained instead of contagious.

The fixture also carried no NonParallelizable while its sibling OlcBTreeStressTests does, so a harness that already spawns five scenario tasks plus its noise threads ran as one of four concurrent heavy fixtures under the assembly's LevelOfParallelism(4). That configuration took the test host down, with ChaosStressTests.UltimateStress_AllSubsystems, SubscriptionStressTests.MultiClient_50Clients_SharedView_AllReceiveDeltas and WalCrashSweepTests.Exhaustive_PageAxis_SingleTxSpawn_N33 in flight alongside it.

On the repaired harness: six runs, 68,123 iterations, no hangs, no crashes, and no missing keys in any scenario. Read no rate published before this change as a property of the tree.

What the working instrument then showed, recorded here because it is what the next step builds on. #738 is not a deadlock: raise OLC_STRESS_ITER_DEADLINE_SECONDS to 300 and the deadlines disappear entirely, replaced by both Add scenarios reaching the MaxPessimisticRestarts bound and throwing "no progress in 10000 pessimistic retries" out of AddOrUpdateCorePessimistic. Same event, two labels. It is the same defect class as #740 and a different instance, since the Add scenarios never call Remove. #739's chunk id reproduces in Remove_Disjoint rather than Remove_Merges, at a stable ChunkId=589824 across separate runs, which is 0x90000 and so a packed field read as a chunk id rather than corruption.
@nockawa
nockawa merged commit a464cf7 into main Aug 10, 2026
14 checks passed
@nockawa
nockawa deleted the olc-738-harness branch August 10, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant