allthingssecurity commented on code in PR #27921:
URL: https://github.com/apache/camel/pull/27921#discussion_r4289667717


##########
components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java:
##########
@@ -845,10 +863,55 @@ private CompletableFuture<Exchange> processTaskAsync(
         return future;
     }
 
+    /**
+     * Makes the write-back of the task and the takeover by the caller (the 
fallback, or the timeout exception) mutually
+     * exclusive, for one call. The task writes its result only if it claims 
the exchange before the caller. The caller
+     * always writes: if it takes over while the write-back of the task is in 
progress, it waits until that is done, and
+     * then works on the exchange that holds the result of the task.
+     */
+    private static final class ExchangeWriteGuard {
+        private final Lock lock = new ReentrantLock();
+        private boolean claimed;
+
+        /**
+         * Claims the exchange for the write-back of the task. When this 
returns true, the lock is held until
+         * {@link #writeBackDone()} is called.
+         */
+        boolean tryClaimForWriteBack() {
+            lock.lock();
+            if (claimed) {
+                lock.unlock();
+                return false;
+            }
+            claimed = true;
+            return true;
+        }
+
+        /**
+         * Ends the write-back of the task, after {@link 
#tryClaimForWriteBack()} returned true.
+         */

Review Comment:
   Thanks, done in 526c608a1d46: the javadoc of `writeBackDone()` now says it 
must be called in a `finally` block, as the lock stays held until then (javadoc 
only). On the backport: I agree camel-4.22.x has the same `AtomicBoolean` guard 
from CAMEL-24134 and camel-4.18.x does not, as the PR description says. I 
cannot set labels on this repository, so a committer would need to add 
`port/camel-4.22.x` if wanted.
   
   _Claude Code on behalf of allthingssecurity_



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