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


##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/ConcurrentRequestsThrottler.java:
##########
@@ -183,14 +183,16 @@ private static void doThrottle(Exchange exchange, 
ThrottlingState throttlingStat
      */
     protected boolean processAsynchronously(
             final Exchange exchange, final AsyncCallback callback, 
ThrottlingState throttlingState) {
+        AsyncCall call = newAsyncCall(exchange, callback);
         try {
             if (LOG.isTraceEnabled()) {
                 exchange.setProperty(PROPERTY_EXCHANGE_QUEUED_TIME, 
TimeSource.nanoTime());
             }
             exchange.setProperty(PROPERTY_EXCHANGE_STATE, State.ASYNC);
-            asyncExecutor.submit(() -> process(exchange, callback));
+            asyncExecutor.submit(call);
             return false;
         } catch (final RejectedExecutionException e) {
+            call.rejected();

Review Comment:
   ⚠️ **Potential double-callback race:** If `doShutdown` fires between 
`newAsyncCall` (which adds to `asyncCalls`) and `submit`, `failAsyncCalls` can 
claim the call and invoke `callback.done(false)` before this catch runs. 
`call.rejected()` is then a no-op (already removed), but 
`isCallerRunsWhenRejected()` could still invoke `process(exchange, callback)` → 
second `callback.done`.
   
   Consider guarding:
   ```suggestion
               if (!asyncCalls.remove(call)) {
                   return false; // already claimed by failAsyncCalls
               }
   ```
   Inserted before the `isCallerRunsWhenRejected` check in the catch block.



##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/DelayProcessorSupport.java:
##########
@@ -130,6 +140,7 @@ protected boolean processDelay(Exchange exchange, 
AsyncCallback callback, long d
                 return false;
             } catch (RejectedExecutionException e) {
                 // we were not allowed to run the ProcessCall, so need to 
decrement the counter here
+                scheduledCalls.remove(call);

Review Comment:
   ⚠️ **Double-decrement race:** If `failScheduledCalls` claims this call 
(removes from `scheduledCalls` + `delayedCount.decrementAndGet` + 
`callback.done`) before `schedule()` throws, then `scheduledCalls.remove(call)` 
here is a no-op but `delayedCount.decrementAndGet()` runs unconditionally → 
counter goes negative.
   
   Consider making the decrement conditional:
   ```suggestion
                   if (scheduledCalls.remove(call)) {
                       delayedCount.decrementAndGet();
                   }
   ```



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