8000 Avoid deleting old client sessions by ahus1 · Pull Request #41548 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Avoid deleting old client sessions - #41548

Merged
ahus1 merged 2 commits into
keycloak:mainfrom
ahus1:is-41427-avoid-concurrent-deletes
Aug 26, 2025
Merged

ahus1 merged 2 commits into
keycloak:mainfrom
ahus1:is-41427-avoid-concurrent-deletes

Conversation

@ahus1
@ahus1 ahus1 commented Jul 30, 2025
Copy link
Copy Markdown
Member

If this is done concurrently, this can load to errors with Hibernate and its optimistic locking

Closes #41427

If this is done concurrently, this can load to errors with Hibernate and its optimistic locking

Closes keycloak#41427

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
@ahus1 ahus1 self-assigned this Jul 30, 2025
@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.

Unreported flaky test detected, please review

@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.federation.ldap.LDAPGroupMapperTest#test06_addingUserToNewKeycloakGroup

Keycloak CI - Base IT (5)

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.federation.ldap.LDAPGroupMapperTest.lambda$test06_addingUserToNewKeycloakGroup$26a8868a$3(LDAPGroupMapperTest.java:656)
...

Report flaky test

@ahus1
ahus1 marked this pull request as ready for review July 31, 2025 06:51
@ahus1
ahus1 requested review from a team as code owners July 31, 2025 06:51
@ahus1
ahus1 marked this pull request as draft July 31, 2025 06:52
@ahus1
ahus1 commented Aug 1, 2025
Copy link
Copy Markdown
Member Author

@lbilger - I've pushed a change that will skip the deletion. Can you give this change a try in a local build?

I might need some more time to come up with a local test in our test suite ... this might happen also only when an item is no longer in the cache?

@ahus1
ahus1 marked this pull request as ready for review August 25, 2025 15:34
@ahus1
ahus1 commented Aug 25, 2025
Copy link
Copy Markdown
Member Author

@pruivo - please give it a review when you have the time. I can't think of a good way to add a test for this, and I would hope the existing tests should suffice for that. Let's hear what you think of this. Thanks!

@pruivo
pruivo commented Aug 25, 2025
Copy link
Copy Markdown
Member

@ahus1 it looks fine to me as it seems a waste of queries/operation to remove expired sessions (the remove expired task will take care of it)

@lbilger
lbilger commented Aug 25, 2025
Copy link
Copy Markdown

Hi @ahus1, some days ago I have deployed a locally-built version of Keycloak including your fix to one of our environments and haven't seen this error there since. So to me it looks like your fix is working. Looking forward to see it merged and released. Thanks a lot for your help!

pruivo
pruivo previously approved these changes Aug 25, 2025
@pruivo
pruivo commented Aug 25, 2025
Copy link
Copy Markdown
Member

@ahus1 if it is ok, may you fix it here too?

AuthenticatedClientSessionAdapter clientAdapter = importClientSession((UserSessionAdapter<?>) userSession, clientSession, getTransaction(true),
getClientSessionTransaction(true), true);
if (clientAdapter == null) {
persister.removeClientSession(userSession.getId(), client.getId(), true);
}

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
@ahus1
ahus1 commented Aug 26, 2025
Copy link
Copy Markdown
Member Author

@pruivo - thanks, I reworked the PR. Please re-review.

@pruivo pruivo left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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.

Parallel token exchange fails if client session is expired

3 participants

0