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

   ## Description
   
   Fixes [CAMEL-26796](https://issues.apache.org/jira/browse/CAMEL-26796).
   
   ### Root cause
   
   In the optimistic `remove()` path, `HazelcastAggregationRepository` 
previously wrote the recovery entry to `persistedCache` **before** the 
compare-and-remove on `cache`. When two threads (or nodes) race on the same 
group they both hold the same exchange (same `exchangeId`, since they both read 
the same stored entry). Both write to `persistedCache[exchangeId]`. When the 
compare-and-remove fails, the losing thread calls 
`removeFromRecoverableStorage()`, which deletes the **winning** thread's 
recovery entry. If the winner's downstream processing later fails, the group is 
irrecoverably lost.
   
   This was introduced by CAMEL-26663 / #29278.
   
   ### Fix
   
   Move the `persistedCache.put()` to **after** the successful 
`cache.remove()`. This is the same order that 
`ReplicatedHazelcastAggregationRepository` already uses correctly.
   
   The two maps cannot be updated atomically regardless of order. With the new 
order, a crash between the two steps means the group re-appears in `cache` on 
restart (duplicate delivery rather than silent loss), which is the safe 
trade-off. The dead-code `removeFromRecoverableStorage()` helper is removed.
   
   ### Tests
   
   - Removed two tests that covered the old cleanup path (no longer exists).
   - Added `checkOptimisticRemoveRaceDoesNotDeleteWinnersRecoveryEntry()`: 
deterministically reproduces the race — add a group, get it twice as `a` and 
`b` (same `exchangeId`), `remove(a)` succeeds, `remove(b)` throws 
`OptimisticLockingException`, then `recover(a.getExchangeId())` must still 
return the group.
   
   _This PR was created by an AI coding agent (Hermes/forgebot) on behalf of 
gnodet._


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