Skip to content

Skip unnecessary provider initialization for non-server commands - #51511

Merged
rmartinc merged 1 commit into
keycloak:mainfrom
mabartos:KC-51506
Aug 10, 2026
Merged

Skip unnecessary provider initialization for non-server commands#51511
rmartinc merged 1 commit into
keycloak:mainfrom
mabartos:KC-51506

Conversation

@mabartos

@mabartos mabartos commented Aug 6, 2026

Copy link
Copy Markdown
Member
Next time you run the server, just add --optimized to the command to ensure this build is used.
2026-08-06 14:53:14,844 INFO  [org.infinispan.CONTAINER] (main) ISPN000974: Virtual threads support: enabled
2026-08-06 14:53:16,153 INFO  [org.hibernate.orm.jdbc.batch] (JPA Startup Thread) HHH100501: Automatic JDBC statement batching enabled (maximum batch size 32)
2026-08-06 14:53:16,200 WARN  [org.keycloak.common.Profile] (main) Deprecated features identity-brokering-api:v1, twitter-broker:v1 enabled by default. Check the upgrading guide for steps to use later versions if available.
2026-08-06 14:53:17,377 INFO  [org.keycloak.quarkus.runtime.storage.database.liquibase.QuarkusJpaUpdaterProvider] (main) Initializing database schema. Using changelog META-INF/jpa-changelog-master.xml
2026-08-06 14:53:21,919 INFO  [org.infinispan.CONTAINER] (main) ISPN000556: Starting user marshaller 'org.infinispan.commons.marshall.ImmutableProtoStreamMarshaller'
2026-08-06 14:53:22,307 INFO  [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_878793, Site name: null, Cluster name: ISPN
2026-08-06 14:53:22,472 INFO  [org.keycloak.quarkus.runtime.storage.database.jpa.DatabaseIndexChecker] (db-index-checker) Running database index checker
2026-08-06 14:53:22,575 INFO  [org.keycloak.services] (main) KC-SERVICES0050: Initializing master realm
2026-08-06 14:53:24,583 INFO  [org.keycloak.services] (main) KC-SERVICES0033: Full model export requested
2026-08-06 14:53:24,583 INFO  [org.keycloak.exportimport.singlefile.SingleFileExportProvider] (main) Exporting model into file /home/mabartos/Documents/RH/keycloak/quarkus/dist/target/keycloak-999.0.0-SNAPSHOT/bin/test-realm.json
2026-08-06 14:53:25,316 INFO  [org.keycloak.services] (main) KC-SERVICES0035: Export finished successfully
2026-08-06 14:53:25,342 INFO  [org.keycloak.services.resources.KeycloakApplication] (main) Bootstrap completed in 9.141 seconds
2026-08-06 14:53:25,365 INFO  [io.quarkus] (main) Keycloak 999.0.0-SNAPSHOT on JVM (powered by Quarkus 3.38.0) started in 14.869s. Listening on: 
2026-08-06 14:53:25,365 INFO  [io.quarkus] (main) Profile nonserver activated. 
2026-08-06 14:53:25,365 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, jdbc-h2, keycloak, narayana-jta, opentelemetry, rest, rest-jackson, smallrye-context-propagation, vertx]
2026-08-06 14:53:26,390 INFO  [com.arjuna.ats.jbossatx] (main) ARJUNA032014: Stopping transaction recovery manager
2026-08-06 14:53:26,504 INFO  [io.quarkus] (main) Keycloak stopped in 1.132s

And these timers are skipped for the non-server command:

2026-08-06 14:54:47,737 DEBUG [org.keycloak.timer.basic.BasicTimerProvider] (main) Ignoring scheduled task 'ClearExpiredRevokedTokens' in non-server mode
2026-08-06 14:54:48,170 INFO  [org.keycloak.services] (main) KC-SERVICES0033: Full model export requested
2026-08-06 14:54:48,170 INFO  [org.keycloak.exportimport.singlefile.SingleFileExportProvider] (main) Exporting model into file /home/mabartos/Documents/RH/keycloak/quarkus/dist/target/keycloak-999.0.0-SNAPSHOT/bin/test-realm.json
2026-08-06 14:54:48,947 INFO  [org.keycloak.services] (main) KC-SERVICES0035: Export finished successfully
2026-08-06 14:54:48,958 DEBUG [org.keycloak.timer.basic.BasicTimerProvider] (main) Ignoring scheduled task 'ClearExpiredEvents' in non-server mode
2026-08-06 14:54:48,959 DEBUG [org.keycloak.timer.basic.BasicTimerProvider] (main) Ignoring scheduled task 'ClearExpiredAdminEvents' in non-server mode
2026-08-06 14:54:48,959 DEBUG [org.keycloak.timer.basic.BasicTimerProvider] (main) Ignoring scheduled task 'ClearExpiredClientInitialAccessTokens' in non-server mode
2026-08-06 14:54:48,959 DEBUG [org.keycloak.timer.basic.BasicTimerProvider] (main) Ignoring scheduled task 'ClearExpiredUserSessions' in non-server mode
2026-08-06 14:54:48,959 DEBUG [org.keycloak.timer.basic.BasicTimerProvider] (main) Ignoring scheduled task 'ClearExpiredIssuedVerifiableCredentials' in non-server mode

Closes keycloak#51506

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
@mabartos
mabartos marked this pull request as ready for review August 6, 2026 12:56
@mabartos
mabartos requested review from a team as code owners August 6, 2026 12:56
Copilot AI balanced review requested due to automatic review settings August 6, 2026 12:56
@mabartos
mabartos marked this pull request as draft August 6, 2026 12:56

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.

Pull request overview

Reduces startup work and timer-related logging for one-shot Keycloak commands.

Changes:

  • Avoids creating or scheduling basic timers in non-server mode.
  • Skips workflow listener setup and Infinispan session expiration tasks.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
BasicTimerProviderFactory.java Avoids timer creation.
BasicTimerProvider.java Ignores scheduling without a timer.
WorkflowsEventListenerFactory.java Skips post-initialization work.
InfinispanUserSessionProviderFactory.java Skips offline-session expiration task startup.

@mabartos
mabartos marked this pull request as ready for review August 7, 2026 11:55
@mabartos
mabartos requested a review from shawkins August 7, 2026 11:55
@mabartos

mabartos commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@shawkins Could you please check it? Thank you!

@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, thanks @mabartos

* Start the expiration task for offline sessions.
* Skipped in non-server mode (export, import) as session expiration is not needed for one-time commands.
*/
private void startExpirationTask(KeycloakSessionFactory factory) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@keycloak/sre @pruivo @ryanemerson Can somebody from the PR team review this small change to cover the ISPN? Thanks!

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.

Looks good to me.

@rmartinc rmartinc 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.

Approving based on previous reviews.

@rmartinc
rmartinc merged commit bc4b813 into keycloak:main Aug 10, 2026
93 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.

Skip unnecessary provider initialization for non-server commands

6 participants