allthingssecurity commented on PR #28645: URL: https://github.com/apache/camel/pull/28645#issuecomment-6494336380
@oscerd thanks, I made it airtight in 26c6ae9, as you suggested. `EhcacheManager` now changes the reference count under its own lock: - `incRef()` starts the manager when nothing used it. - `decRef()` returns the new count, and the user that releases the last reference stops the manager. That user can be the endpoint, a producer or a consumer. - `shutdownIfUnused()` shuts it down only at 0. The endpoint's `doStart`/`doStop`/`doShutdown` use these instead of reading `getReferenceCount()` themselves. While checking it, I also found that the count's first-use and last-release callbacks (`CacheManager.init`/`close`) ran outside any lock. So a user that started while the last one closed the cache manager could take its reference on the cache manager being closed. The same lock covers that now. New tests in `EhcacheManagerTest` (no sleeps): - `aUserThatStartsWhileTheLastOneClosesTheCacheManagerWaitsForTheClose`: deterministic. A user starts from inside the cache manager's `close()`. It must wait, and then find the manager started and AVAILABLE with count 1. With the lock removed from `incRef`/`decRef`, it fails in 20 of 20 runs (`Init not supported from AVAILABLE`, or `expected: <0> but was: <1>`). - `exactlyOneOfTheLastUsersThatStopTogetherStopsTheManager`: 16 threads × 100 rounds, exactly one sees 0. This is a stress test; without the lock that window is too narrow to hit in 20 runs. - `theLastUserStopsTheManagerAlsoWhenItIsNotTheEndpoint`. camel-ehcache: 83 tests, 0 failures. `EhcacheManagerTest` and `EhcacheRemoveRouteTest` each passed 20 runs in one JVM. `decRef()` (protected) now returns `long` instead of `void`; nothing outside the package uses it. _Claude Code on behalf of allthingssecurity_ -- 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]
