Repository navigation
Fix flaky RealmInvalidationClusterTest by waiting for cluster cache sync - #55349
Merged
Merged
Conversation
ruchikajha95
force-pushed
the
fix-55346-cluster-cache-sync
branch
from
November 19, 2026 11:33
fa115c9 to
1876945
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The failback readiness check excludes the restarted node, so it can return while that node is still isolated and leave the next update exposed to the same race.
1 open issue
What changed in this PR
This PR aims to reduce the flaky realm invalidation failure reported in #55346 by adding a post-failback consistency wait to the shared cluster-test base.
Changes:
- Adds entity-state polling with a 10-second timeout and 100ms interval.
- Calls the wait after failback, before rotating the failure node.
- Logs synchronization progress and performs a final consistency assertion on timeout.
| File | Description |
|---|---|
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cluster/AbstractInvalidationClusterTest.java |
Adds post-failback consistency polling and timeout diagnostics. |
Review effort: Balanced
Replace blind sleep after failback() with condition-based polling that actively verifies cache consistency across all backend nodes before proceeding. This prevents race conditions during split-brain recovery where cache invalidation events have not fully propagated. The new waitForClusterSync() method: - Polls ALL backend nodes (not just survivors) for entity consistency - Ensures the restarted node has rejoined and received invalidations - Returns immediately once synchronized (typically < 1 second) - Has a 10-second timeout with detailed failure diagnostics - Uses TimeUnit.MILLISECONDS.sleep() for polling (no external deps) This addresses the root cause of flaky failures where the test would immediately check cache consistency after failback without waiting for Infinispan cluster rebalancing to complete. Closes keycloak#55346 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Ruchika <Ruchika.Jha1@ibm.com>
ruchikajha95
force-pushed
the
fix-55346-cluster-cache-sync
branch
from
November 19, 2026 12:46
1876945 to
5f27d75
Compare
ahus1
approved these changes
Nov 19, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The recovery wait can return before cluster membership is restored because matching values may come from the shared database, and the initial failback path still updates entities without waiting, leaving invalidation races unresolved.
2 open issues
1 resolved since last review
Review effort: Balanced
Comment on lines
+180
to
+184
| if (allNodesConsistent) { | ||
| long elapsed = System.currentTimeMillis() - startTime; | ||
| log.info(String.format("Cluster cache synchronized successfully across all %d nodes after %dms", | ||
| getClusterSize(), elapsed)); | ||
| return; |
Comment on lines
+236
to
+237
| // Wait for cluster rebalancing to complete after failback | ||
| waitForClusterSync(testEntity); |
This was referenced Nov 19, 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.
Closes #55346
After failback() brings killed nodes back online, the test immediately proceeds without waiting for Infinispan cluster rebalancing to complete, causing race conditions when cache invalidation events have not fully propagated during split-brain recovery.
Decisions and assumptions