allthingssecurity commented on PR #30623:
URL: https://github.com/apache/camel/pull/30623#issuecomment-7094482110

   Thanks for the careful review. All changes are in 07a7c6fe6f.
   
   1. Lock scope. Agreed. `stopEvicted` now takes the producer out of the pool 
under the lock (just the field swap, as `SinglePool.stop()` does), then stops 
it and removes it from the CamelContext without the lock, and only then takes 
the lock for `isEndpointInUse` + `doStop(endpoint)`. The order matters: the 
evicted producer is stopped and removed first, so it no longer counts as using 
the endpoint, and the in-use check and the endpoint stop stay under the lock 
that creates producers, so a producer that a new pool of the endpoint creates 
meanwhile is either seen by the check or created after it. I changed the model 
the same way (swap under the lock, stop outside, second lock around check + 
endpoint stop) and ran it again: no violation, 2 threads, 2 singleton 
endpoints, cache size 1: 2,837,143 distinct states (3,772,351 with the fast 
path, 2,110,126 with one singleton and one non-singleton endpoint), same counts 
with TLC and everystate. A variant of the new model without the lock aro
 und the check and the endpoint stop still finds an endpoint stopped under a 
producer in use (EpNotStoppedInUse, 846,276 distinct states), so that part of 
the lock is needed. The case the model still finds with "no producer created on 
a stopped endpoint" is the one listed under "Not changed" (a cache that 
resolved the endpoint before it was stopped), same as main and the first commit.
      On the thread: on main the evicted producer was also stopped on a caller 
thread, either by `onEvict` on the thread whose acquire overflowed the cache, 
or by `cleanupEvicts` on the next acquire or release of any singleton producer 
of the cache, and `DefaultProducerCache` releases in the async callback before 
`callback.done`, so main could also stop it on an I/O thread before the caller 
continues. With the change it is the evicting thread (producer idle) or the 
last releaser of that producer. So the kind of thread does not change, only 
which caller pays, and now it is the caller that used the producer rather than 
an unrelated one. With the stop out of the lock it no longer holds up producer 
creation for other endpoints, so I did not add an executor.
   
   2. Null from the creator. Done: `SinglePool.acquire` throws 
`IllegalStateException("No service created from endpoint: ...")` when the 
creator returns null, so the retry loop only retries after an eviction or stop. 
Test: `ProducerCacheSingletonEvictionTest.testCreatorReturningNullFails` (fails 
at once, and again on the next acquire; on the first commit it spins until the 
pool is stopped).
   
   3. Hot path cost. Understood, no code change here. If the maintainers want 
it lower, keeping a pool handle next to `lastUsedProducer` on the fast path (no 
map lookup) could be a follow-up; the two increments stay, as any count of the 
users of a shared producer needs them.
   
   Nits:
   
   - Stop of an evicted pool in use through `SinglePool.stop()`: fixed. When 
the `ServicePool` stops (or the cache is purged) and an evicted producer is 
still in use, `stop()` now also stops the dynamic endpoint if nothing else uses 
it, as `cleanupEvicts` did on main. Test: 
`testStopOfThePoolStopsTheEndpointOfAnEvictedProducerInUse`.
   - The TRACE log hook: replaced. `SinglePool.acquire` calls a package-private 
no-op `ServicePool.onSingleAcquired(s)` after it read and counted the producer, 
and the test moved to 
`org.apache.camel.support.cache.SinglePoolAcquireEvictionTest` (camel-core 
tests, same package), which pauses there. No log level change any more.
   - Unbalanced callers: in `DefaultRestOpenapiProcessorStrategy`, if 
`p.process(...)` throws synchronously the callback never runs, so the release 
is missed (and `callback.done` too). It is not a one-liner (it needs a 
try/catch that releases without releasing twice) and it is in another module, 
so I left it for a follow-up and did not touch it here.
   
   Tests: on the first commit the two new tests in 
`ProducerCacheSingletonEvictionTest` fail (the null creator spins until the 
pool is stopped, and the endpoint stays started); with the change the two 
classes 20 times in one JVM: 160 run, 0 failures. camel-support 181 run, 0 
failures, 5 skipped (and 181 in its virtual threads run); the ProducerCache, 
ConsumerCache, ServicePool, toD, recipientList, enrich, pollEnrich, eviction 
and LRU cache tests of camel-core: 931 run, 0 failures, 2 skipped.
   


-- 
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