fix(tonic-xds): consume immediate first tick in OD housekeeping actor#2689
Merged
gu0keno0 merged 2 commits intoJun 16, 2026
Merged
Conversation
`tokio::time::interval(period)` returns immediately on its first poll, so the actor was running `run_housekeeping` at t≈0 — before the data path had recorded anything. That early sweep called `snapshot_and_reset` on whatever counters had landed, zeroing them. In tests this surfaces as a race: `test_outlier_detection_reinsert_preserves_state` flakes with `(0, 0) != (3, 0)` when the actor's first tick fires after the test records its 3 calls but before the assertion reads counters. In production this silently drops the first interval's worth of outcomes on every endpoint. Fix: consume the immediate tick before entering the loop so the first real sweep happens one full `interval` after spawn, matching what the gRFC A50 sweep semantics expect. Verified the test passes 10/10 under stress.
Contributor
|
Thanks for the fix. maybe https://docs.rs/tokio/latest/tokio/time/fn.interval_at.html is a better way? |
gu0keno0
approved these changes
Jun 16, 2026
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.
Summary
A flaky test was reported (link) after #2619 was merged.
The root cause is:
tokio::time::interval(period)fires immediately on its first poll, so the outlier-detection housekeeping actor was runningrun_housekeepingat t≈0 — before the data path had recorded anything. That early sweep callssnapshot_and_resetand zeros whatever counters have landed. Therefore,test_outlier_detection_reinsert_preserves_stateflakes with(0, 0) != (3, 0)when the actor's first tick races the assertion read.Fix: consume the immediate tick before entering the loop so the first real sweep fires one full
intervalafter spawn, matching the gRFC A50 semantics.Testing
`cargo test -p tonic-xds --lib test_outlier_detection_reinsert_preserves_state` — 10/10 pass under stress.