Skip to content

Conversation

@berry120
Copy link
Contributor

MetricsAutoConfiguration contains a MeterRegistryCloser that ensures MeterRegistry instances are closed early in the shutdown process. However, this currently works by closing all such instances when any application context is closed. In the case where a child application context is created and then closed but the application is still running (i.e. the root context hasn't closed), the closure of this child context will then close all MeterRegistry instances prematurely.

(As a real-world example - when using the initializr library and calling ProjectGenerationInvoker.invokeProjectStructureGeneration, a ProjectGenerationContext is created, and then closed before the method returns - this then closes all the MeterRegistry instances defined in the application calling the initializr library.)

This fix ensures that the closure only happens when the root application context is being closed.

(I believe this is my first PR here, so happy to correct anything I may have done wrong!)

@wilkinsona
Copy link
Member

Thanks for identifying the problem and proposing a fix. Unfortunately, I don't think this is quite right.

The currently proposed change will leave open indefinitely a meter registry that belongs to a child context. Instead, I think the closer should only close the beans from the current context and should only react to a close event that comes from that context. The beans can be retrieved using context.getBeansOfType(MeterRegistry.class).values(). Would you like to update your PR to this effect? If you'd prefer, feel free to open an issue instead and we can take things from here.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Nov 28, 2025
@wilkinsona wilkinsona changed the title Fix: Actuator incorrectly closes MeterRegistry on child context closing Parent's MeterRegistry beans are closed when child context closes Nov 28, 2025
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 28, 2025
@berry120
Copy link
Contributor Author

@wilkinsona Good point - I hadn't considered that. Now updated.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 28, 2025
@wilkinsona wilkinsona self-assigned this Nov 28, 2025
@wilkinsona wilkinsona removed the status: feedback-provided Feedback has been provided label Nov 28, 2025
@wilkinsona wilkinsona added this to the 3.4.x milestone Nov 28, 2025
@wilkinsona wilkinsona modified the milestones: 3.4.x, 3.4.13 Nov 28, 2025
wilkinsona pushed a commit that referenced this pull request Nov 28, 2025
@wilkinsona
Copy link
Member

Thanks for the updates, @berry120. I've merged the changes with a few modifications so that a child context's registries are still closed when the child is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants