Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.micrometer.core.instrument.Clock;
import io.micrometer.statsd.StatsdConfig;
import io.micrometer.statsd.StatsdMeterRegistry;
import jakarta.annotation.PreDestroy;

import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
Expand Down Expand Up @@ -59,4 +60,8 @@ public StatsdMeterRegistry statsdMeterRegistry(StatsdConfig statsdConfig, Clock
return new StatsdMeterRegistry(statsdConfig, clock);
}

@PreDestroy
public void destroy(StatsdMeterRegistry statsdMeterRegistry) {
statsdMeterRegistry.close();
}
}
Copy link
Contributor

@mdeinum mdeinum Sep 18, 2024

Choose a reason for hiding this comment

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

This won't work as @PreDestroy should not have any arguments (See https://jakarta.ee/specifications/platform/9/apidocs/jakarta/annotation/predestroy).

Finally as the StatsdMeterRegistry has a close method that should already be registered automatically as a pre-destroy method. For this see the @Bean.

So the solution to the problem lies not in adding additional annotations but probably elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, @mdeinum. I was just going to comment with the same analysis.

@popotec can you please open an issue so that we can investigate further? Seeing the stack trace of the exception when bean creation is attempted during shutdown may be enough for us to figure out the cause.