test: fix racy mt_record_static (refresh raced recorder drops) - #155
Open
fcostaoliveira wants to merge 1 commit into
Open
test: fix racy mt_record_static (refresh raced recorder drops)#155fcostaoliveira wants to merge 1 commit into
fcostaoliveira wants to merge 1 commit into
Conversation
mt_record_static refreshed and read h.len() before joining the recording threads, so refresh() raced the Recorders being dropped. A dropped Recorder's samples are only guaranteed visible to the *next* refresh(), so the single racing refresh undercounts by whole per-recorder histograms (observed ~1.1-1.3M instead of 1.6M, ~10/15 runs on a 96-core box). No data is lost -- a subsequent refresh recovers it, so this is a test ordering bug, not a library defect. Join all recording threads first (which drops every Recorder), then refresh and read. Deterministic afterwards (25/25 locally). The HdrHistogram#151 cleanup fixed record_nodrop and recorder_drop_staged but left this instance. Co-Authored-By: Claude Opus 4.8 <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.
What
tests/sync.rs::mt_record_staticis flaky: it intermittently undercounts the total. On a 96-core machine it fails ~10 of 15 runs (observed totals 1.1–1.3M instead of 1.6M); it also reproduces on an 8-core laptop (~3/20). The shortfall is always a whole multiple of the per-thread count (100 000) — i.e. entire per-recorder histograms are missing.Why
The test refreshes and reads
h.len()before joining the recording threads:The
Barrieronly guarantees recording finished — not that theRecorders have been dropped. A liveRecorder's samples become visible torefresh()only when it is dropped (or a later write observes the bumped phase), and a drop makes them visible to the nextrefresh(). Becauseh.len()(the assert's left operand) is evaluated before the.join()on the right,refresh()runs concurrently with the threads returning and dropping their recorders, so it can return before folding in the stragglers. No data is lost — a subsequentrefresh()recovers it — so this is a test-ordering bug, not a library defect.Fix
Join all recording threads first (dropping every
Recorder), establishing happens-before, thenrefresh()and read:Deterministic afterwards: 25/25 locally (was ~3/20). Test-only change; no library code touched. This is the same anti-pattern #151 fixed in
record_nodrop/recorder_drop_staged— this instance was missed.🤖 Generated with Claude Code