shashank created CAMEL-26302:
--------------------------------

             Summary: camel-ehcache - removing the route that consumes from a 
cache closes the cache that the other routes still use, so every cache action 
fails with "State is UNINITIALIZED"
                 Key: CAMEL-26302
                 URL: https://issues.apache.org/jira/browse/CAMEL-26302
             Project: Camel
          Issue Type: Bug
          Components: camel-ehcache
            Reporter: shashank
            Assignee: shashank


When a route is removed, the core stops and shuts down the endpoint of its 
consumer ({{RouteService.doShutdown}}), also when other routes still use the 
same endpoint. For an ehcache endpoint this releases caches that other routes 
still hold (main c536c99caaaa):

* {{EhcacheEndpoint.doStop}} (line 112) releases the endpoint's reference on 
its {{EhcacheManager}}. Without {{cacheManager}}, {{cacheManagerConfiguration}} 
or {{configurationUri}} the endpoint has its own cache manager, so this is the 
last reference and it closes the {{CacheManager}} with all its caches.
* {{EhcacheEndpoint.doShutdown}} (line 118) shuts the {{EhcacheManager}} down, 
which closes every cache it created without a configuration 
({{EhcacheManager.doShutdown}}, line 66). With {{cacheManager}}, 
{{cacheManagerConfiguration}} or {{configurationUri}} the manager is shared by 
all the endpoints that use it, so this closes the caches of other endpoints too.

The producers of the other routes keep the {{Cache}} they got when they were 
created, so from then on every action (PUT, GET, ...) fails with 
{{IllegalStateException: State is UNINITIALIZED}}, also after the removed route 
is added again. Nothing else is logged.

Examples:
# {{from("ehcache:orders?configuration=#ordersConfig")}} (a route that reacts 
to cache events) and {{to("ehcache:orders?configuration=#ordersConfig")}} in 
other routes. As each endpoint uri without a cache manager option has its own 
cache manager (CAMEL-26237), a consumer and a producer of the same cache must 
use the same uri, so they share the endpoint. Removing the event route breaks 
the producer routes.
# {{cacheManager=#myManager}} on all endpoints, with some caches configured in 
the manager and others created on demand: removing a route that consumes events 
of a configured cache closes the on-demand caches of the other endpoints.

A route is removed by a route reload (dev mode, route watcher), a removed route 
template or Kamelet, JMX or the control bus.

*Fix*: the producers and consumers hold a reference on the {{EhcacheManager}} 
while they are started (as the endpoints already do), so the cache manager is 
closed by the last of them; an endpoint shuts the {{EhcacheManager}} down only 
when nothing uses it any more, and the last reference also closes the caches 
created without a configuration (an endpoint shut down with a removed route is 
not shut down again). {{EhcacheManagerTest}} now counts the producers too (4 
references for two endpoints with their producers instead of 2).

*Tests*: new {{EhcacheRemoveRouteTest}}: {{removeEventRouteOfSameEndpoint}}, 
{{removeEventRouteOfSharedCacheManager}}, {{removeEventRouteThenAddItAgain}} 
and {{removeEventRouteThenStopClosesCacheCreatedOnDemand}} fail on main (3 
runs, each with {{IllegalStateException: State is UNINITIALIZED}} on the first 
action after the removal) and pass with the fix. With the fix camel-ehcache has 
77 tests, 0 failures.

*How it was found*: a code sweep for endpoints whose {{doStop}} releases 
something that other routes on the same uri still use, after a random 
lifecycle-sequence harness found the same kind of defect in camel-disruptor 
(CAMEL-26286).

*Affected*: main, camel-4.22.x, camel-4.18.x and camel-4.14.x (same 
{{doStop}}/{{doShutdown}}; read, not run).

*Related*: CAMEL-26237 (each endpoint uri without a cache manager option builds 
its own cache manager; a consumer on a cache without configuration gets no 
events). Sharing the default cache manager per component, as proposed there, 
would make the second case above the default one.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to