Parent's MeterRegistry beans are closed when child context closes#48319
Parent's MeterRegistry beans are closed when child context closes#48319berry120 wants to merge 2 commits intospring-projects:mainfrom
Conversation
Signed-off-by: Michael Berry <[email protected]>
|
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 |
Signed-off-by: Michael Berry <[email protected]>
|
@wilkinsona Good point - I hadn't considered that. Now updated. |
See gh-48319 Signed-off-by: Michael Berry <[email protected]>
|
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. |
MetricsAutoConfigurationcontains aMeterRegistryCloserthat ensuresMeterRegistryinstances 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 allMeterRegistryinstances prematurely.(As a real-world example - when using the initializr library and calling
ProjectGenerationInvoker.invokeProjectStructureGeneration, aProjectGenerationContextis created, and then closed before the method returns - this then closes all theMeterRegistryinstances 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!)