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


##########
core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java:
##########
@@ -1062,6 +1064,11 @@ public void setInterrupted(boolean interrupted) {
         }
     }
 
+    @Override
+    public long nextAwaitOrder() {
+        return ++awaitOrder;

Review Comment:
   ⚠️ **Concurrency note:** `++awaitOrder` is a non-atomic read-modify-write on 
a plain `long` field. The design intent is that calls to `nextAwaitOrder()` are 
sequential within a routing chain (outer `process()` call happens before the 
inner one via `Thread.start()` happens-before), which makes this safe in the 
typical nested-waiter scenario.
   
   However, the `nextAwaitOrder()` contract is undocumented in this regard: it 
says "each time a thread calls it", which hints at concurrent access. If 
`await(Exchange, CountDownLatch)` is ever called concurrently by external code 
on the same exchange, this will race. `AtomicLong` would make it robust:
   
   ```suggestion
       private final java.util.concurrent.atomic.AtomicLong awaitOrder = new 
java.util.concurrent.atomic.AtomicLong();
   ```
   
   And the method:
   ```java
       @Override
       public long nextAwaitOrder() {
           return awaitOrder.incrementAndGet();
       }
   ```
   
   Alternatively, document the sequential-access assumption in the 
`ExchangeExtension.nextAwaitOrder()` Javadoc so future readers know why a plain 
`long` is safe here.



##########
core/camel-api/src/main/java/org/apache/camel/spi/AsyncProcessorAwaitManager.java:
##########
@@ -176,6 +179,14 @@ default String getNodeSource() {
      * Though if it appears as the exchange is <i>stuck</i>, then this method 
can remedy this, by forcing the latch to
      * count-down so the blocked thread can continue. An exception is set on 
the exchange which allows Camel's error
      * handler to deal with this malfunctioned exchange.
+     * <p>
+     * When more than one thread waits for the exchange, only the thread whose
+     * {@link #process(AsyncProcessor, Exchange)} call started last is 
released. This is a nested wait: a thread waits
+     * for the exchange while the exchange goes on, on another thread, through 
a step that waits for it too (such as
+     * {@code ProducerTemplate.send(uri, exchange)}). The released inner 
thread goes on with the failed exchange to the

Review Comment:
   💬 **Doc clarity:** The sentence starting with "This is a nested wait:" runs 
to ~31 words across three Javadoc lines, exceeding the recommended 25-word 
limit. Consider splitting:
   
   > _"This is a nested wait. One thread waits for the exchange while the 
exchange, on another thread, enters a step that also waits for it (such as 
`ProducerTemplate.send(uri, exchange)`). The inner thread proceeds with the 
failed exchange to the end of its route, and the callback then releases the 
outer thread."_



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