allthingssecurity opened a new pull request, #30574: URL: https://github.com/apache/camel/pull/30574
# Description [CAMEL-27320](https://issues.apache.org/jira/browse/CAMEL-27320) The idempotent read locks (`readLock=idempotent`, `idempotent-changed` and `idempotent-rename`) compute the key of the file in `asKey`. With an `idempotentKey`, `asKey` evaluates the expression on a dummy exchange made by `GenericFileHelper.createDummy`, which copies the headers of the routed exchange. The key was computed again at commit, rollback and abort, so at that point it was evaluated on the headers the route left behind, not on the ones the file had when the lock was acquired. `${file:name}` and the other file expressions read `CamelFileName`, and a route sets that header before a file producer all the time. So with `idempotentKey=${file:name}` and a route that sets `CamelFileName`: - a route that fails is rolled back, and with the default `readLockRemoveOnRollback=true` the read lock removes a key that was never added (for example `out-hello.txt`). The key it added (`hello.txt`) stays in the repository, and the file stays in the inbox and is never picked up again, by any node. With a persistent repository (JDBC, Infinispan, ...) this survives a restart; - with `readLockRemoveOnCommit=true` the commit removes the key the new name evaluates to. If that is the key of a file another node is processing, that file can be picked up and processed a second time while the first node still works on it, and the own key is left behind. `GenericFileConsumer` already keeps the key it computed for `idempotent=true` on the exchange (`CamelFileIdempotentKey`) for the same reason, and CAMEL-24093 fixed a similar mismatch for `preMove` (4.22). The fix: `acquireExclusiveReadLock` keeps the key it computed on the exchange (a per-file property next to the existing `CamelFileLockIdempotentAcquired` one), and the commit, rollback and abort release that key. If the property is missing (a strategy used without its acquire, or a route that removed all properties) the key is computed as before. The same change in the three strategies. Model: the bug was found with a TLA+ model of clustered consumption with an idempotent read lock (nodes, a shared repository, release delay, route and move failures, crashes). I added the fix to it (release the key of the acquire). On main it finds a rolled back file that is never picked up again, a node that removes another node's key, and a file processed by two nodes. With the fix all properties hold (at-most-once, no foreign removal, rolled back files retryable, no ghost run with a release delay), with 3 nodes, 2 files and up to 2 failures of each kind: 187,622 distinct states with `readLockRemoveOnCommit=true` and a delay, 69,345 with the defaults (TLC and everystate agree). Tests: new `FileIdempotentReadLockRoutedFileNameTest`, for each of the three read locks: - a route that sets `CamelFileName` and fails on the first attempt: the file must be picked up again and completed, and the repository must hold only its key; - a route that sets `CamelFileName` to the name of a file whose key another node holds, with `readLockRemoveOnCommit=true`: the commit must remove its own key and keep the other one. On main all 6 fail (the file is never retried; the other node's key is removed and the own key kept). With the change they pass, and so do the file tests in camel-core and camel-file: 601 run, 0 failures, 12 skipped. The new class 20 times in one JVM: 120 run, 0 failures. No upgrade guide entry: the released key is now the one the documentation describes. Not changed: - A read lock key still has no expiry: if a node dies while it holds a key, the file is not picked up until the key is removed (by the repository's own expiry, if it has one, or by hand). # 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): [CAMEL-27320](https://issues.apache.org/jira/browse/CAMEL-27320). # 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. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
