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


##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/SemanticEvaluateConsole.java:
##########
@@ -76,6 +78,8 @@ private synchronized ExecutorService executor() throws 
Exception {
     @Override
     protected synchronized void doStart() throws Exception {
         stopped = false;
+        active.drainPermits();
+        active.release(2);

Review Comment:
   ⚠️ **Permit leak on restart**: `doStop()` calls `shutdownNow()` without 
awaiting executor termination. If `doStart()` runs before in-flight lambdas 
execute their `finally { active.release(); }`, `drainPermits()` sees 
fewer-than-expected permits, `release(2)` resets to 2, and those deferred 
lambda releases push the count above 2.
   
   Subsequent calls to `tryAcquire()` will succeed more than 2 at a time until 
the extra permits are consumed. The window is narrow (stop/start while tasks 
are mid-flight) but the fix is simple:
   
   ```suggestion
           active.drainPermits();
           active.release(2);
   ```
   
   Consider either:
   - Awaiting executor termination in `doStop()` with a brief timeout before 
returning (so by the time `doStart()` runs, all lambdas have released), or
   - Replacing `Semaphore` with `AtomicInteger` and a CAS-based `compareAndSet` 
guard that bounds at exactly 2, making out-of-range releases a no-op.



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