Defer initialization of JGroups after logging is set up by Quarkus (#29131)

Closes #29129

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2024-05-14 12:38:37 +02:00 committed by GitHub
parent 3d1c20b4a5
commit 701e49e4a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,6 +17,8 @@
package org.keycloak.quarkus.deployment; package org.keycloak.quarkus.deployment;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.logging.LoggingSetupBuildItem;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import org.keycloak.quarkus.runtime.KeycloakRecorder; import org.keycloak.quarkus.runtime.KeycloakRecorder;
import org.keycloak.quarkus.runtime.storage.legacy.infinispan.CacheManagerFactory; import org.keycloak.quarkus.runtime.storage.legacy.infinispan.CacheManagerFactory;
@ -27,12 +29,16 @@ import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
public class CacheBuildSteps { public class CacheBuildSteps {
@Consume(ConfigBuildItem.class) @Consume(ConfigBuildItem.class)
@Record(ExecutionTime.STATIC_INIT) // Consume LoggingSetupBuildItem.class and record RUNTIME_INIT are necessary to ensure that logging is set up before the caches are initialized.
// This is to prevent the class TP in JGroups to pick up the trace logging at start up. While the logs will not appear on the console,
// they will still be created and use CPU cycles and create garbage collection.
// See: https://issues.redhat.com/browse/JGRP-2130 for the JGroups discussion, and https://github.com/keycloak/keycloak/issues/29129 for the issue Keycloak had with this.
@Consume(LoggingSetupBuildItem.class)
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep @BuildStep
void configureInfinispan(KeycloakRecorder recorder, BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItems, ShutdownContextBuildItem shutdownContext) { void configureInfinispan(KeycloakRecorder recorder, BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItems, ShutdownContextBuildItem shutdownContext) {
syntheticBeanBuildItems.produce(SyntheticBeanBuildItem.configure(CacheManagerFactory.class) syntheticBeanBuildItems.produce(SyntheticBeanBuildItem.configure(CacheManagerFactory.class)