You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "Croway (via GitHub)" <gi...@apache.org> on 2026/04/09 15:16:10 UTC

[PR] CAMEL-23294: fix orphan lock race in JDBC idempotent repository [camel]

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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23294: fix orphan lock race in JDBC idempotent repository [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22515:
URL: https://github.com/apache/camel/pull/22515#issuecomment-4215358959

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23294: fix orphan lock race in JDBC idempotent repository [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22515:
URL: https://github.com/apache/camel/pull/22515#issuecomment-4215654421

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-sql`
   
   <details><summary>All tested modules (9 modules)</summary>
   
   - Camel :: JBang :: MCP
   - Camel :: JBang :: Plugin :: Route Parser
   - Camel :: JBang :: Plugin :: Validate
   - Camel :: JTA
   - Camel :: Kafka
   - Camel :: Launcher :: Container
   - Camel :: SQL
   - Camel :: YAML DSL :: Validator
   - Camel :: YAML DSL :: Validator Maven Plugin
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/24198009485)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23294: fix orphan lock race in JDBC idempotent repository [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #22515:
URL: https://github.com/apache/camel/pull/22515#issuecomment-4215868097

   Please wait some time before merging in case the reporter of the issue Roman Stechkevych replies with the github username for co autorship https://issues.apache.org/jira/browse/CAMEL-23294 


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23294: fix orphan lock race in JDBC idempotent repository [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #22515:
URL: https://github.com/apache/camel/pull/22515


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23294: fix orphan lock race in JDBC idempotent repository [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #22515:
URL: https://github.com/apache/camel/pull/22515#issuecomment-4223579172

   merging as we need to get the branches ready for releasing ...


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org