Repository navigation
test(registrar): make the watch-filter re-assert test ordering-immune (#772) - #793
Merged
Merged
Conversation
VERDICT: test artefact, not a production bug. The watch loop is correct;
the in-process fake's request log is not ordered the way the assertion
assumed.
`TestWatchLoop_FilterReassertIsNeverLost` asserted that the LAST request
recorded by `fakeWatchServer` carried the newest filter. But the fake
appends to `s.requests` from inside `WatchEndpoints`, and grpc-go
dispatches every server stream on its own goroutine
(`watch_startup_test.go:51`). When the loop cancels stream N and
immediately opens stream N+1 — which is exactly what each of the test's
4-deep bursts makes it do — the two handler goroutines race to append,
and N's request can land after N+1's. Once the burst settles, the fake
holds the live stream open forever and no further request arrives, so
`lastRequest()` reports the superseded stream's filter permanently and
the 10s `require.Eventually` can never converge.
Interleaving trace, captured by instrumenting the fake to dump its whole
request log on failure (7/7 observed failures, identical shape):
req[39] filter=[default/svc-33-3]
req[40] filter=[default/svc-34-3] <- the wanted filter DID reach the server
req[41] filter=[default/svc-34-2] <- an OLDER stream's handler appending late
active streams: 1
i.e. the loop opened a stream asserting svc-34-3 and was sitting on it,
doing precisely the right thing, while the test reported it "stuck on a
stream with a stale filter". In all 7 failures the wanted filter was
present exactly once in the request log and the final entry was an
earlier round-member (svc-N-2 or svc-N-1).
Production is correct and no window remains:
- `assertFilter` (registrar.go:284-290) publishes this stream's
canceller and reads the filter under ONE `filterMu` hold, so a
concurrent `SetServiceFilter` either completes first (the loop reads
the new filter) or completes after (it captures THIS stream's
canceller at registrar.go:238 and cancels it at registrar.go:257).
"Neither" is unrepresentable — that is #781's fix, and it holds.
- `SetServiceFilter` cancelling late (after the cache purge at
registrar.go:245-255) is harmless: it cancels the exact stream it
captured, and if the loop has already moved on, its next
`assertFilter` necessarily read a filter at least as new, because
the critical sections are totally ordered on `filterMu`.
- Two rapid updates both capturing the same canceller (the test's
burst) converge: whichever cancel lands first reconnects the loop,
and the reconnect's `assertFilter` reads the newest filter; the
second cancel is a no-op on a dead stream.
- #612's reconnect semantics are untouched: a locally-cancelled stream
is classified out of the failure path (registrar.go:843-847,
registrar.go:585-590), so no backoff accumulates across the 40
rounds and the cap-1 wake / CompareAndSwap paths are not involved.
Test changes only:
- `watch_startup_test.go`: add `sawFilter`, the ordering-immune
predicate — "some stream asserted exactly this filter". It loses no
strength, because a genuinely lost re-assert leaves its filter in no
request at all. Document the ordering hazard on `lastRequest`; its
other caller asserts `requestCount() == 1` so it is unaffected.
- `watch_filter_test.go`: assert on `sawFilter`, and pass `logs`
(a Stringer) instead of `logs.String()` — testify evaluates message
args eagerly, so the pre-rendered string captured the log from
BEFORE the 10s wait and never showed what actually happened. That
alone cost most of the diagnosis time on the original CI failure.
Failure rates (race detector, `taskset -c 0,1` to mimic a 2-core runner):
before: 2/30 on the shipped test; 7/40 on an instrumented copy
after: 0/60 on the test, 0/30 on the whole package
Also 30/30 green via
`bazel test //registry/internal/registrar:registrar_test --config=race
--runs_per_test=30 --nocache_test_results` (whole package, unfiltered).
Verification: `bazel build //... //test/e2e:e2e_test`, `bazel test //...`
(101/101), `bazel run //:format.check`, `bazel build --config=lint
--@aspect_rules_lint//lint:fail_on_violation //...`, `bazel run
//:gazelle` (no churn), `bazel mod tidy` (idempotent),
`scripts/go-deps-audit.sh` (exit 0).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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.
Follow-up to #781: the fake server's request log is appended by concurrent stream handlers, so the assertion raced. Production loop verified correct.
fix(registrar): make the filter re-assert test deterministic (#772)
VERDICT: test artefact, not a production bug. The watch loop is correct;
the in-process fake's request log is not ordered the way the assertion
assumed.
TestWatchLoop_FilterReassertIsNeverLostasserted that the LAST requestrecorded by
fakeWatchServercarried the newest filter. But the fakeappends to
s.requestsfrom insideWatchEndpoints, and grpc-godispatches every server stream on its own goroutine
(
watch_startup_test.go:51). When the loop cancels stream N andimmediately opens stream N+1 — which is exactly what each of the test's
4-deep bursts makes it do — the two handler goroutines race to append,
and N's request can land after N+1's. Once the burst settles, the fake
holds the live stream open forever and no further request arrives, so
lastRequest()reports the superseded stream's filter permanently andthe 10s
require.Eventuallycan never converge.Interleaving trace, captured by instrumenting the fake to dump its whole
request log on failure (7/7 observed failures, identical shape):
i.e. the loop opened a stream asserting svc-34-3 and was sitting on it,
doing precisely the right thing, while the test reported it "stuck on a
stream with a stale filter". In all 7 failures the wanted filter was
present exactly once in the request log and the final entry was an
earlier round-member (svc-N-2 or svc-N-1).
Production is correct and no window remains:
assertFilter(registrar.go:284-290) publishes this stream'scanceller and reads the filter under ONE
filterMuhold, so aconcurrent
SetServiceFiltereither completes first (the loop readsthe new filter) or completes after (it captures THIS stream's
canceller at registrar.go:238 and cancels it at registrar.go:257).
"Neither" is unrepresentable — that is fix(registrar,node): copy cached endpoints out of the lock, never lose a watch-filter re-assert, atomic Diff+Replace, optimistic-lock taint patches (#772) #781's fix, and it holds.
SetServiceFiltercancelling late (after the cache purge atregistrar.go:245-255) is harmless: it cancels the exact stream it
captured, and if the loop has already moved on, its next
assertFilternecessarily read a filter at least as new, becausethe critical sections are totally ordered on
filterMu.burst) converge: whichever cancel lands first reconnects the loop,
and the reconnect's
assertFilterreads the newest filter; thesecond cancel is a no-op on a dead stream.
is classified out of the failure path (registrar.go:843-847,
registrar.go:585-590), so no backoff accumulates across the 40
rounds and the cap-1 wake / CompareAndSwap paths are not involved.
Test changes only:
watch_startup_test.go: addsawFilter, the ordering-immunepredicate — "some stream asserted exactly this filter". It loses no
strength, because a genuinely lost re-assert leaves its filter in no
request at all. Document the ordering hazard on
lastRequest; itsother caller asserts
requestCount() == 1so it is unaffected.watch_filter_test.go: assert onsawFilter, and passlogs(a Stringer) instead of
logs.String()— testify evaluates messageargs eagerly, so the pre-rendered string captured the log from
BEFORE the 10s wait and never showed what actually happened. That
alone cost most of the diagnosis time on the original CI failure.
Failure rates (race detector,
taskset -c 0,1to mimic a 2-core runner):before: 2/30 on the shipped test; 7/40 on an instrumented copy
after: 0/60 on the test, 0/30 on the whole package
Also 30/30 green via
bazel test //registry/internal/registrar:registrar_test --config=race --runs_per_test=30 --nocache_test_results(whole package, unfiltered).Verification:
bazel build //... //test/e2e:e2e_test,bazel test //...(101/101),
bazel run //:format.check,bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...,bazel run //:gazelle(no churn),bazel mod tidy(idempotent),scripts/go-deps-audit.sh(exit 0).🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr