Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise dynamic bean registrations with the IntegrationFlowContext #9442

Closed
artembilan opened this issue Sep 4, 2024 · 0 comments · Fixed by #9450
Closed

Revise dynamic bean registrations with the IntegrationFlowContext #9442

artembilan opened this issue Sep 4, 2024 · 0 comments · Fixed by #9450

Comments

@artembilan
Copy link
Member

More info on StackOverflow: https://stackoverflow.com/questions/78933787/why-does-spring-not-clean-up-integrationflows-for-a-dynamic-tcp-client.

Apparently there is a memory leak when we remove bean definitions and the cache for their merged bean definition is not clear due to: spring-projects/spring-framework#23336.

The problem has a big impact when random bean names are used for the IntegrationFlowContext interaction.

Need to look into a way to deal with a SingletonBeanRegistry.registerSingleton() instead of a BeanDefinitionRegistry.registerBeanDefinition().

@artembilan artembilan added this to the 6.4.0-M3 milestone Sep 4, 2024
artembilan added a commit to artembilan/spring-integration that referenced this issue Sep 10, 2024
Fixes: spring-projects#9442
Issue link: spring-projects#9442

When we register a `BeanDefinition`, its metadata is cached in the `DefaultListableBeanFactory.mergedBeanDefinitionHolders`
and it is not removed when we destroy bean.
This causes a memory leak with dynamic integration flows where even we destroy beans, their metadata is still cached.
This has more serious impact when random ids are used for dynamic integration flows.

* Rework `IntegrationFlowContext` logic to register singletons instead of `BeanDefinition`
* Adjust `IntegrationFlowBeanPostProcessor` logic to register singletons or `BeanDefinition`
according to the presence of `BeanDefinition` of the `IntegrationFlow` we are processing
* Introduce `ComponentSourceAware` to mimic a `BeanDefinition` metadata logic for bean source and its description.
This info helps a lot with exceptions where class in the `IntegrationFlow` might be fully from a Spring Integration package.
So, to give a clue what end-user code is related to the exception,
such a `ComponentSourceAware` is there to preserver and transfer "bean source"
* Implement `ComponentSourceAware` in the `IntegrationObjectSupport` since this is a central
place where we generate info for the Spring Integration exceptions
* Implement `ComponentSourceAware` in the `StandardIntegrationFlow` to propagate bean source info
down to its components for the mentioned `IntegrationObjectSupport` logic
* Introduce inner `StandardIntegrationFlowContext.IntegrationFlowComponentSourceAwareAdapter`
to be able to transfer "bean source" info from builder down to the target `IntegrationFlow` bean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant