8000 [26.6] Realm session limit is exceeded by mabartos · Pull Request #48105 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[26.6] Realm session limit is exceeded - #48105

Merged
ahus1 merged 1 commit into
keycloak:release/26.6from
mabartos:backport-48064-26.6
Apr 15, 2026
Merged

ahus1 merged 1 commit into
keycloak:release/26.6from
mabartos:backport-48064-26.6

Conversation

@mabartos
Copy link
Copy Markdown
Member
  • when the realm session limit is exceeded and behavior is set to Terminate oldest session, the authenticator calls
    handleLimitExceeded(userSessionsForClient, userClientLimit) first.

if the user has fewer existing sessions for the current client than userClientLimit - 1, getNumberOfSessionsThatNeedToBeLoggedOut() returns a negative value and Stream.limit(negative) throws
IllegalArgumentException, producing a 500 on every login to that client.

This change ensures that getNumberOfSessionsThatNeedToBeLoggedOut returns 0 if the calculated value is negative.
The dependent execution steps remain unchanged.
A result of 0 sessions to be purged from the current client triggers the removal of the oldest sessions across all clients.

also added a regression test in UserSessionLimitsTest that reproduces the scenario: realm limit=2, client limit=3, two logins on client-a to saturate the realm, then login on client-b (0 existing client sessions).

Fixes #48040


Signed-off-by: Martin Krcka martin.krcka@adesso.de
Signed-off-by: Martin Bartoš mabartos@redhat.com
Co-authored-by: Mateen Anjum mateenali66@gmail.com
Co-authored-by: Martin Bartoš mabartos@redhat.com
(cherry picked from commit 953cd26)

@ahus1 IMHO, it might be backported to the 26.6.

keycloak#48064)

* when the realm session limit is exceeded and behavior is set to Terminate oldest session, the authenticator calls
handleLimitExceeded(userSessionsForClient, userClientLimit) first.

if the user has fewer existing sessions for the current client than userClientLimit - 1, getNumberOfSessionsThatNeedToBeLoggedOut() returns a negative value and Stream.limit(negative) throws
IllegalArgumentException, producing a 500 on every login to that client.

This change ensures that getNumberOfSessionsThatNeedToBeLoggedOut returns 0 if the calculated value is negative.
The dependent execution steps remain unchanged.
A result of 0 sessions to be purged from the current client triggers the removal of the oldest sessions across all clients.

also added a regression test in UserSessionLimitsTest that reproduces the scenario: realm limit=2, client limit=3, two logins on client-a to saturate the realm, then login on client-b (0 existing client sessions).

Fixes keycloak#48040

---------

Signed-off-by: Martin Krcka <martin.krcka@adesso.de>
Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Co-authored-by: Mateen Anjum <mateenali66@gmail.com>
Co-authored-by: Martin Bartoš <mabartos@redhat.com>
(cherry picked from commit 953cd26)
@mabartos
mabartos requested a review from ahus1 April 15, 2026 14:20
@mabartos
mabartos requested review from a team as code owners April 15, 2026 14:20
@mabartos mabartos changed the title when the realm session limit is exceeded and behavior is set to Termi… (#48064) [26.6] Realm session limit is exceeded Apr 15, 2026
@mabartos mabartos linked an issue Apr 15, 2026 that may be closed by this pull request
1 of 2 tasks
@ahus1
ahus1 enabled auto-merge (squash) April 15, 2026 14:32
@ahus1
ahus1 merged commit c66069c into keycloak:release/26.6 Apr 15, 2026
78 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.

User session limit generates fatal error

3 participants

0