gnodet-bot commented on code in PR #27921:
URL: https://github.com/apache/camel/pull/27921#discussion_r4289588426
##########
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:
`tryClaimForWriteBack()` returns `true` with the lock held — an accidental
call without a `writeBackDone()` `finally` block deadlocks the next caller
permanently. Document the contract:
```suggestion
/**
* Ends the write-back of the task, after {@link
#tryClaimForWriteBack()} returned true.
* Must be called in a {@code finally} block.
*/
```
--
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]