Federico Mariani created CAMEL-24182:
----------------------------------------

             Summary: camel-cxf - SpringBusFactoryBean never shuts down the bus 
it creates (Bus/BusApplicationContext leak)
                 Key: CAMEL-24182
                 URL: https://issues.apache.org/jira/browse/CAMEL-24182
             Project: Camel
          Issue Type: Bug
          Components: camel-cxf
            Reporter: Federico Mariani
            Assignee: Federico Mariani


*Severity:* High

h3. Problem
{{SpringBusFactoryBean}} is a singleton, eager-init {{SmartFactoryBean<Bus>}} 
whose {{getObject()}} runs {{new SpringBusFactory().createBus(cfgFiles, 
includeDefaultBus)}}, creating a full {{BusApplicationContext}} (its own Spring 
context) plus bus thread pools/extensions. The class implements no 
{{DisposableBean}} and declares no destroy method, and Spring never destroys 
FactoryBean *products*. CXF only closes the {{BusApplicationContext}} when 
{{bus.shutdown()}} is called - which nothing ever does.

h3. Impact
An application that declares {{<bean class="...SpringBusFactoryBean">}} and 
wires the bus into endpoints leaks the bus, its {{BusApplicationContext}}, 
workqueue threads and classloader references on every context close/refresh 
(servlet redeploy, Spring Boot devtools restart, repeated integration tests) -> 
thread/memory leak, eventually metaspace/OOM on repeated redeploys.

h3. Location
{{components/camel-cxf/camel-cxf-spring-common/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java}}
 ~32-75.

h3. Fix
Implement {{DisposableBean}} and retain the created bus:
{code:java}
public void destroy() { if (bus != null) { bus.shutdown(true); } }
{code}
Also add a null-guard in {{setCfgFiles}} (currently NPEs on null) and remove 
the write-only {{bf}} field.

----
_Filed by Claude Code (Claude Fable) on behalf of Federico Mariani (GitHub: 
Croway). Findings from an AI-assisted code review of the camel-cxf component 
family; each item was verified against the current source and git history. 
Items marked *[reproducer attached]* include a failing JUnit test that 
demonstrates the defect._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to