fix(mvcc): deterministic GC Dispose (fixes flaky DisposeStopsBackgroundCollectionTest on main)#5
Merged
Merged
Conversation
…stic stop) DisposeStopsBackgroundCollectionTest flaked on main after #4 (Expected 5, was 6): MvccGarbageCollector.Dispose() called Timer.Dispose(), which does NOT wait for an already-running callback. A collection cycle that started just before Dispose could finish and bump RunCount afterwards, so 'no runs after Dispose' held only when the timing happened to cooperate (green on the PR runner, red on main). Use the Timer.Dispose(WaitHandle) overload and wait for the handle: it signals once all callbacks have drained, so no background collection runs after Dispose returns and RunCount is final. Pre-existing race in a subsystem untouched by #4 - just surfaced by runner timing. MVCC GC fixture 14/14, stable across repeated runs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mainwent red after #4 merged:MvccGarbageCollectorTests.DisposeStopsBackgroundCollectionTestfailed withExpected: 5, But was: 6. It passed on the #4 PR run and failed on the post-mergemainrun on the same code — a timing-dependent flake, not introduced by #4.Root cause
MvccGarbageCollector.Dispose()calledTimer.Dispose(), which does not wait for an already-running timer callback. A collection cycle that started just beforeDispose()could complete and incrementRunCountafterDispose()returned, so the test's "no runs after Dispose" invariant only held when timing cooperated. Pre-existing race in a subsystem untouched by #4 — the noisymainrunner just surfaced it.Fix
Use the
Timer.Dispose(WaitHandle)overload and wait on the handle — it signals once all callbacks have drained, guaranteeing no background collection runs afterDispose()returns andRunCountis final. (Same shutdown-correctness shape as the LsmParallelWriter fix in #4.)Verification
MvccGarbageCollectorTests14/14, stable across repeated local runs (was intermittently 5-vs-6).🤖 Generated with Claude Code