Skip to content

(KC24) Use Dedicated SQL Session for Truststore#21

Merged
JBWatenbergScality merged 7 commits intohotfix-1.4.2-24.0.3from
bugfix/backport-add-retry-logic-on-connection-closed
Feb 25, 2026
Merged

(KC24) Use Dedicated SQL Session for Truststore#21
JBWatenbergScality merged 7 commits intohotfix-1.4.2-24.0.3from
bugfix/backport-add-retry-logic-on-connection-closed

Conversation

@JBWatenbergScality
Copy link
Copy Markdown
Contributor

@JBWatenbergScality JBWatenbergScality commented Dec 2, 2025

Context:
JDBC Connection gets closed under load after some time.

What Changed:
Replace retry/cache complexity with executeInNewSession for reads
getCertificates() and getCertificates(boolean) now always execute in a
fresh Keycloak session via KeycloakModelUtils.runJobInTransaction(),
obtaining a new JDBC connection from the pool. This replaces the
previous approach of em.clear() (which did not reset the connection),
manual retry loops, flush mode manipulation, and in-memory cache
fallback — none of which reliably handled the cold-start case where the
current session's connection is closed.

How was it validated
Verified 1000/1000 under concurrent load (10 workers, no delay).

…toreProvider to handle connection closed errors
@JBWatenbergScality JBWatenbergScality changed the title Implement retry logic for database operations in JpaCertificateTrusts… Implement retry logic for database operations in JpaCertificateTruststoreProvider to handle connection closed errors Dec 2, 2025
JBWatenbergScality and others added 6 commits December 2, 2025 13:37
…rors by setting flush mode to COMMIT during query execution. This prevents issues related to pending changes during cascade operations and improves retry logic for connection and flush errors.
getCertificates() and getCertificates(boolean) now always execute in a
fresh Keycloak session via KeycloakModelUtils.runJobInTransaction(),
obtaining a new JDBC connection from the pool. This replaces the
previous approach of em.clear() (which did not reset the connection),
manual retry loops, flush mode manipulation, and in-memory cache
fallback — none of which reliably handled the cold-start case where the
current session's connection is closed.

Verified 1000/1000 under concurrent load (10 workers, no delay).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@JBWatenbergScality JBWatenbergScality changed the title Implement retry logic for database operations in JpaCertificateTruststoreProvider to handle connection closed errors Use Dedicated SQL Session for Truststore Feb 25, 2026
@JBWatenbergScality JBWatenbergScality changed the title Use Dedicated SQL Session for Truststore (KC24) Use Dedicated SQL Session for Truststore Feb 25, 2026
@JBWatenbergScality JBWatenbergScality merged commit 0870237 into hotfix-1.4.2-24.0.3 Feb 25, 2026
6 checks passed
@JBWatenbergScality JBWatenbergScality deleted the bugfix/backport-add-retry-logic-on-connection-closed branch February 25, 2026 09:00
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.

1 participant