gnodet-bot commented on code in PR #28645:
URL: https://github.com/apache/camel/pull/28645#discussion_r4411393147


##########
components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConsumer.java:
##########
@@ -53,18 +54,32 @@ protected void doStart() throws Exception {
         if (configuration.getValueType() != null) {
             vt = 
getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getValueType());
         }
-        this.cache = getEndpoint().getManager().getCache(cacheName, kt, vt);
+        EhcacheManager endpointManager = getEndpoint().getManager();
+        this.cache = endpointManager.getCache(cacheName, kt, vt);
 
         this.cache.getRuntimeConfiguration().registerCacheEventListener(
                 this,
                 configuration.getEventOrdering(),
                 configuration.getEventFiring(),
                 configuration.getEventTypesSet());
+        // the cache manager (and its caches) are kept while the consumer uses 
them
+        endpointManager.incRef();
+        this.manager = endpointManager;

Review Comment:
   💡 **Ordering inconsistency vs `EhcacheProducer`**: the producer takes its 
reference (`incRef()`) before obtaining the cache, so the manager is guaranteed 
open before any cache access. Here the consumer does the reverse: `getCache()` 
and `registerCacheEventListener()` run before `incRef()`, relying on the 
endpoint's own reference to keep the manager alive. The fix is safe today, but 
the inconsistency makes the invariant harder to verify. Reorder to match the 
producer:
   
   ```suggestion
           EhcacheManager endpointManager = getEndpoint().getManager();
           // the cache manager (and its caches) are kept while the consumer 
uses them
           endpointManager.incRef();
           this.manager = endpointManager;
           this.cache = endpointManager.getCache(cacheName, kt, vt);
   
           this.cache.getRuntimeConfiguration().registerCacheEventListener(
                   this,
                   configuration.getEventOrdering(),
                   configuration.getEventFiring(),
                   configuration.getEventTypesSet());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to