gnodet-bot commented on code in PR #30304:
URL: https://github.com/apache/camel/pull/30304#discussion_r4609990939
##########
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();
if (isCallerRunsWhenRejected()) {
Review Comment:
⚠️ **Race 1 not fixed — `isCallerRunsWhenRejected()` runs unconditionally
after a void `rejected()`.**
`call.rejected()` removes the task from `asyncCalls` if it's still there,
but returns `void`. If `failAsyncCalls` already claimed and `callback.done`'d
the exchange before the `RejectedExecutionException` catch fires, `rejected()`
is a no-op — and execution falls through to `process(exchange, callback)` →
double `callback.done`.
Fix: return `boolean` from `rejected()` and guard the caller-runs block:
In `AbstractThrottler.AsyncCall`:
```java
boolean rejected() {
return asyncCalls.remove(this);
}
```
Then here:
```java
if (!call.rejected()) {
return false; // doShutdown already failed this exchange
}
if (isCallerRunsWhenRejected()) {
```
##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/TotalRequestsThrottler.java:
##########
@@ -201,9 +202,10 @@ protected boolean processAsynchronously(
// exchanges and not yet returned, so try again after one period
long delay = next != null
? next.getDelay(TimeUnit.NANOSECONDS) :
TimeUnit.MILLISECONDS.toNanos(getTimePeriodMillis());
- asyncExecutor.schedule(() -> process(exchange, callback), delay,
TimeUnit.NANOSECONDS);
+ asyncExecutor.schedule(call, delay, TimeUnit.NANOSECONDS);
return false;
} catch (final RejectedExecutionException e) {
+ call.rejected();
if (isCallerRunsWhenRejected()) {
Review Comment:
⚠️ **Race 1 also present here — identical pattern to
`ConcurrentRequestsThrottler`.**
`call.rejected()` (void) followed by `if (isCallerRunsWhenRejected())` with
no guard. If `failAsyncCalls` claimed the call first, `process(exchange,
callback)` runs → double `callback.done`. Same fix applies (make `rejected()`
return `boolean`, guard before the caller-runs path).
##########
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);
delayedCount.decrementAndGet();
Review Comment:
⚠️ **Race 2 not fixed — `delayedCount.decrementAndGet()` runs
unconditionally after a discarded `remove` result.**
`scheduledCalls.remove(call)` is now called (progress), but the return value
is thrown away. If `failScheduledCalls` already removed this call and
decremented `delayedCount`, this catch block decrements it again → counter goes
negative → delayed-exchange bookkeeping is permanently wrong for this instance.
Fix: guard the decrement on the atomic remove result:
```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]