allthingssecurity opened a new pull request, #26785:
URL: https://github.com/apache/camel/pull/26785

   # Description
   
   [CAMEL-24941](https://issues.apache.org/jira/browse/CAMEL-24941)
   
   With `closeCorrelationKeyOnCompletion`, the closed-key check in 
`AggregateProcessor.doProcess` ran before the aggregation lock was taken, and 
with optimistic locking it ran only once, before the retry loop. Suppose an 
exchange passed the check while another thread was completing the group for the 
same key (by size, predicate, timeout or force completion). It then waited for 
the lock and was aggregated into a new group for the already closed key. That 
group completed again later, so the key produced two aggregated exchanges, and 
the late exchange wasn't rejected with `ClosedCorrelationKeyException`.
   
   This change: check the closed correlation keys again once the lock is held. 
The check also runs on every optimistic-locking retry. The first check is kept 
as a fast path.
   
   Tests: new `AggregateClosedCorrelationKeyRaceTest`. A strategy pauses the 
completing thread until the next exchange is waiting for the lock, so the race 
is deterministic and there are no sleeps. The late exchange must be rejected, 
and the key must complete only once. Two cases are covered: an exchange waiting 
for the lock, and an optimistic-locking retry after the key was closed. Without 
the fix, both fail (`Expected ClosedCorrelationKeyException but was: null`). 
With the fix, all `*Aggregat*` tests pass: 236 tests, 0 failures (5 
pre-existing skips).
   
   Found with a TLA+ model of the Aggregate EIP (duplicate completion of a 
closed key), then reproduced against the real classes.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built and tested the affected modules, including the formatter and 
import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   


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