Croway opened a new pull request, #22515: URL: https://github.com/apache/camel/pull/22515
## Summary _Claude Code on behalf of Federico Mariani_ Fixes a race condition in `JdbcOrphanLockAwareIdempotentRepository` where multiple application instances can simultaneously acquire the same orphan lock, causing duplicate processing when used with `readLock=idempotent`. **Root cause:** Two bugs working together: 1. `AbstractJdbcMessageIdRepository.add()` ignores `insert()`'s return value — always returns `true` when `queryForInt()` returned 0 2. `JdbcOrphanLockAwareIdempotentRepository.insert()` performs an unconditional `UPDATE` for orphan recovery, so every instance succeeds **Fix:** - `add()` now checks `insert()`'s return value: returns `false` when `insert()` returns 0 (lock not acquired) - `insert()` uses a conditional `UPDATE ... WHERE createdAt < ?` for orphan recovery — only one instance can claim an orphan lock (the first to update makes `createdAt` current; subsequent updates match 0 rows) **Design choice:** Keeps the check-then-act pattern (no `DuplicateKeyException` catching) to avoid PostgreSQL transaction abort issues — this was the motivation for the [2023 rewrite](https://github.com/apache/camel/pull/9286). The fix is database-agnostic. **Reproducer results (500 orphan locks, 2 concurrent instances, PostgreSQL):** | Version | Duplicates | Instance-1 | Instance-2 | |---------|-----------|-----------|-----------| | 4.18.1 (before) | **398** | 59 | 43 | | 4.19.0-SNAPSHOT (after) | **0** | 266 | 234 | ## Test plan - [x] New concurrency test: two repository instances race on the same orphan lock — asserts only one acquires it - [x] All existing `JdbcOrphanLockAwareIdempotentRepositoryTest` tests pass (5/5) - [x] All existing `JdbcMessageIdRepositoryTest` tests pass (2/2) - [x] All existing `CustomizedJdbcMessageIdRepositoryTest` and `JdbcMessageIdRepositoryCustomTableNameTest` pass - [x] External reproducer against PostgreSQL confirms fix with 500 concurrent entries -- 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]
