8000 Defer the revoked token reload until the cache topology has settled by ahus1 · Pull Request #55414 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Defer the revoked token reload until the cache topology has settled - #55414

Merged
ahus1 merged 2 commits into
keycloak:mainfrom
ahus1:is-55413-flaky-revoked-token-reload
Nov 25, 2026
Merged

ahus1 merged 2 commits into
keycloak:mainfrom
ahus1:is-55413-flaky-revoked-token-reload

Conversation

@ahus1
@ahus1 ahus1 commented Nov 20, 2026 •
Copy link
Copy Markdown
Member

Closes #55413

The cache manager view event is delivered before Infinispan has recovered the cache topology after a merge, so a reload triggered from it can write entries that are discarded when the partitions are reconciled.

Decisions and assumptions

  • The view listener only flags that a reload is needed. A @TopologyChanged listener on the actionTokens cache runs the reload once the cache is AVAILABLE, the join is complete and no rehash is running. This keeps the existing rule that joins don't trigger a database scan, as only a merge or a member loss sets the flag.
  • Assumption: a merge or a member loss always produces a topology change for this cache. If none follows, the reload doesn't run; there is no fallback timer.
  • "Settled" also requires the cache topology members to equal the cluster view members, as Infinispan can publish an intermediate topology during a merge that has no rebalance but still lacks the other partition. This is derived from a review comment and the Infinispan source, not from a reproduction.
  • The settled check and the flag consumption run under the same monitor as the scan, so a task queued behind a running scan checks the topology again before it starts its own.
  • Both listeners run on notification threads, so they only check or set the flag. The settled check and the database scan run on the executor.
  • The flag is guarded by a ReentrantLock, as the notification threads that set and read it may be virtual threads. The scan keeps synchronized, as it always runs on the executor's platform threads.
  • The root cause is a hypothesis based on the CI log timing. The reload logs only at debug level, so it is not confirmed. A rerun of the failing jobs is the check.
  • The test now waits for the cluster to contain exactly the test nodes, and both nodes pass a barrier, before splitting it, to fail early with a clear message if a node of a previous test is left over.
  • No backport: the commit that added the reload isn't in the release branches.

Closes keycloak#55413

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
@ahus1
ahus1 force-pushed the is-55413-flaky-revoked-token-reload branch from 32273ba to 9582f3c Compare November 20, 2026 14:15
@ahus1
ahus1 requested a balanced review from Copilot November 20, 2026 14:15
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical races in the reload logic can allow revoked-token scans during topology reconciliation and clear the pending flag before merge recovery completes, preventing a retry.

3 open issues
What changed in this PR

This PR addresses the recovery-timing hypothesis behind #55413 by deferring persisted revoked-token reloads until the actionTokens cache appears settled, rather than starting them directly from cluster view notifications.

Changes:

  • Adds lock-protected pending state and a topology listener, with settled-state checks and database scans running on the executor.
  • Adds an exact-member-count wait before the split-brain test partitions the cluster.
File Description
testsuite/​model/​src/​test/​java/​org/​keycloak/​testsuite/​model/​infinispan/​EmbeddedInfinispanSplitBrainTest.java Waits for the expected cluster size before splitting.
model/​infinispan/​src/​main/​java/​org/​keycloak/​models/​sessions/​infinispan/​InfinispanSingleUseObjectProviderFactory.java Defers pending revocation reloads to cache topology notifications and adds listener cleanup.

Review effort: Balanced

@ruchikajha95 ruchikajha95 left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ahus1

Relates to keycloak#55413

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.broker.KcSamlBrokerTest#testWithLinkedFederationProvider

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Security-sensitive revoked-token recovery depends on unconfirmed notification-ordering and topology-convergence assumptions without a fallback retry, requiring affected CI runs and split-brain runtime validation.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@ahus1
ahus1 marked this pull request as ready for review November 20, 2026 16:23
@ahus1
ahus1 requested review from a team as code owners November 20, 2026 16:23
@ahus1
ahus1 enabled auto-merge (squash) November 20, 2026 16:23
@ruchikajha95 ruchikajha95 left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the recent commits , The changes are stable and lgtm . Thanks @ahus1

@shawkins shawkins left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think I need to pick up this change for #54909

@ahus1
ahus1 merged commit 22a7108 into keycloak:main Nov 25, 2026
157 of 159 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: org.keycloak.testsuite.model.infinispan.EmbeddedInfinispanSplitBrainTest#testRevokedTokensReloadedOnMergeEvent

4 participants

0