8000 KEYCLOAK-19701 Load offline client session after evicted while user session is still in cache by lexcao · Pull Request #8671 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

KEYCLOAK-19701 Load offline client session after evicted while user session is still in cache - #8671

Closed
lexcao wants to merge 1 commit into
keycloak:mainfrom
lexcao:KEYCLOAK-19701
Closed

lexcao wants to merge 1 commit into
keycloak:mainfrom
lexcao:KEYCLOAK-19701

Conversation

@lexcao
@lexcao lexcao commented Oct 31, 2021
Copy link
Copy Markdown
Contributor

…ession is still in cache.

* remove deprecated `getClientSession` implementation
* add new query to `OFFLINE_CLIENT_SESSION`
@mposolda
mposolda commented Jan 3, 2022 •
Copy link
Copy Markdown
Contributor

Thanks for the fix. However I think that it is rather a problem with your configuration as I pointed in the JIRA comment https://issues.redhat.com/browse/KEYCLOAK-19701 . Right now, Keycloak doesn't support to limit size in "offlineSessions" and "offlineClientSessions" caches.

I think if we ever want to support download of the "evicted" sessions from the DB, it would need to be done more properly as lookup of the session by ID is just one scenario, but there are others (For example when user or administrator displays all sessions in account mgmt or admin console and he needs to query sessions rather than simply lookup them by ID).

@hmlnarik @martin-kanis @sguilhen My vote is to close this PR, but leaving this to you as well as JIRA.

@mposolda
mposolda self-requested a review January 3, 2022 16:47
@graziang
graziang commented Feb 8, 2022
Copy link
Copy Markdown
Contributor

I've the same problem with 500k offline sessions on two nodes in production. Any tips for offlineClientSessions and offlineSessions caches tuning?

@ghilainm
ghilainm commented May 17, 2022 •
Copy link
Copy Markdown

I got the same issue ("Session doesn't have required client") but have no clue about how it happened. I don't know either how to reproduce. I am not in production, I have not a lot of sessions, I have one Keycloak node, and I use the default infinite span cache settings. I am using Kecyloak 18.x.x.

@SimonMacIntyre
SimonMacIntyre commented Jun 2, 2022 •
Copy link
Copy Markdown

We are also experiencing this issue with quay.io/keycloak/keycloak:18.0.0-legacy

Sorry, something went wrong.

@thomasdarimont
thomasdarimont commented Jun 2, 2022 •
Copy link
Copy Markdown
Contributor

I've seen this problem quite often in practice as well. The problem that this PR addresses often arises in scenarios where keycloak is used as an IdP / OpenID provider for mobile apps which quite often use large quantities (~100k - ~10Mio) of offline-sessions.

If all offline-sessions are kept in memory, then the resource consumption of a single Keycloak instance can grow to 10s of GBs, even if most offline-sessions aren't accessed! To reduce memory consumption (and cost!) developers often try to limit the amount of cache entries while relying on the lazy offline-session fetching mechanism. Unfortunately, due to the lack of lazy-loading of offline-client sessions users are effectively logged from their apps of the offline-session gets evicted from memory, although there are still valid offline-sessions in the database.
This usually leads to a poor user experience and eventually bad app reviews.

I think it would be very beneficial for a lot of users if offline-session /offline-client-session retrieval would be more robust and would allow a more resource-conserving approach.

Regarding the possibility to list offline-sessions in the admin-console: Actually I've rarely seen admins using this functionality, especially if the number of offline sessions goes beyond a certain limit.

As a current workaround users could create their own InfinispanUserSessionProvider and implement the InfinispanUserSessionProvider#getClientSession as shown in the PR.

@davidfrickert
Copy link
Copy Markdown

We are also experiencing this issue.
It's kind of weird how "offlineSessions" are fetched from DB but "offlineClientSessions" aren't.
We are using Keycloak for the exact scenario that @thomasdarimont described, and don't want to have millions of entries in cache when they could be lazily fetched from DB...
Since Keycloak doesn't intend on supporting this scenario I guess we'll just patch it.

@martin-kanis
Copy link
Copy Markdown
Member

Closing in favour of #17490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

0