spring-framework: Application hangs on startup after upgrading to Spring Boot 3.2.1 with spring-data-redis and micrometer-prometheus dependencies

After upgrading spring-boot to 3.2.1, I encountered an issue where the application hangs on startup. This occurs specifically when using spring-data-redis with enabled keyspace events on startup, in conjunction with the micrometer-prometheus dependencies.

Steps to Reproduce

I have prepared minimal code to reproduce this issue. Below is a simplified version of the build.gradle and DemoApp.java files:

build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version "3.2.1"
}

repositories {
    mavenLocal()
    mavenCentral()
}

apply plugin: 'io.spring.dependency-management'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-redis'
    runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
    runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
    runtimeOnly 'io.micrometer:micrometer-tracing-bridge-brave'
}

wrapper {
    gradleVersion = "8.5"
}

DemoApp.java

@SpringBootApplication
@EnableRedisRepositories(enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP)
public class DemoApp {

    public static void main(String[] args) {
        new SpringApplication(DemoApp.class).run(args);
        System.out.println("Complete!");
    }
}

Observations

  • The issue persists across both Spring Boot versions 3.2.1 and 3.2.0.
  • The application starts normally without hanging when using Spring Boot version 3.1.7 and below.

Additional Information

In a typical scenario, the project includes entity and repository classes, along with other dependencies. However, the provided code is a minimal representation.

  • Removing enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP or changing its value to ON_DEMAND or OFF allows the application to start correctly.

  • Removing any of the dependencies results in the application starting correctly.

  • Disabling Prometheus metrics export by setting management.prometheus.metrics.export.enabled=false in application.properties also allows the application to start correctly.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (18 by maintainers)

Most upvoted comments

@scottfrederick My team is facing a similar issue in production. It seems that currently both this issue and https://github.com/spring-projects/spring-data-redis/issues/2814 were closed and labelled as for external-project. May I know if there’s any team working on this bug? If so, can you point me to that team please? Thank you

In Micrometer, if you don’t provide SpanContext it will not sample Exemplars. I guess the feature you are asking could be a Boot property to not auto-configure it.

You can also create your own @Bean of PrometheusMeterRegistry where you don’t inject any SpanContext which disables Exemplars.

You can also create your own @Bean of SpanContext where you return false in isCurrentSpanSampled and null in the getters.

It’s a hack but Micrometer and Boot also supports some of the Prometheus Client Properties, if you set sampleIntervalMilliseconds high enough you effectively disable Exemplars. Also, this will not solve the bean creation issue mentioned above since auto-configuration will do the same.

If you want to exclude dependencies, you need to exclude Micrometer Tracing otherwise auto-configuration will try to create a SpanContext for it.