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

   # Description
   
   [CAMEL-27285](https://issues.apache.org/jira/browse/CAMEL-27285)
   
   Route A `transacted("PROPAGATION_REQUIRES_NEW")` calls route B 
`transacted("PROPAGATION_REQUIRES_NEW")`, with the same policy bean, through 
`to("direct:b")`. Since CAMEL-8424 the `TransactionErrorHandler` of B starts a 
new transaction there. Its `processInTransaction` calls 
`beginTransactedBy(key)` and `endTransactedBy(key)` with the same key as A (the 
key is the transaction template). The unit of work keeps the keys in a `Set`, 
so when B ends it removes A's key, and `exchange.isTransacted()` is `false` for 
the rest of route A, although it still runs in A's transaction. The same 
happens with a REQUIRED route of another policy in between.
   
   The EIPs that stay on the thread only for a transacted exchange then hand 
the message to another thread, outside the thread-bound Spring transaction: the 
Delay EIP (`asyncDelayed` is the default), Throttle with `asyncDelayed`, 
Threads, and a delayed redelivery with `asyncDelayedRedelivery`. The steps that 
run there are not part of A's transaction: a database insert is committed on 
its own, and stays when A rolls back.
   
   Fix: `processInTransaction` marks and unmarks the unit of work only when the 
key was not marked yet, so the outer transaction keeps its mark.
   
   Model: a small TLA+ model (`TxNesting.tla`: nested transacted routes of a 
REQUIRES_NEW and a REQUIRED policy, up to three deep, the unit of work's Set of 
keys) checks that inside an open transaction the exchange is transacted. On 
main TLC finds A(REQUIRES_NEW) -> B(same policy) -> back in A with no key; with 
the change it holds (15 distinct states).
   
   Tests: `TransactionErrorHandlerNestedRequiresNewTest`, the first unit test 
of camel-spring (test dependencies `camel-core` and `junit-jupiter` added to 
its pom): a `SpringTransactionPolicy` with PROPAGATION_REQUIRES_NEW over a 
small `AbstractPlatformTransactionManager` that records its transactions and 
supports suspend/resume. (Each transacted route has two transaction error 
handlers, the route's and the `transacted()` one, so with REQUIRES_NEW a route 
runs two transactions, as CAMEL-12263 describes; the test checks the 
transactions the steps run in, not counts.) Route A calls route B (same 
policy), then `delay(1)` and a step that records the transaction it runs in. 
Expected: B runs in a transaction of its own, the exchange is still transacted 
after B, and the step after the delay runs in A's transaction; with a failure 
at the end of A, B's transaction commits and A's rolls back. On main both tests 
fail: `isTransacted()` is `false` after B, and the step after the delay runs on 
a s
 cheduler thread without a transaction. With the change both pass (camel-spring 
has no other unit tests; the camel-spring-xml transaction tests were not run 
locally, as that module cannot be built offline here; CI runs them). The new 
class 20 times in one JVM: 40 run, 0 failures.
   
   The camel-jta transaction error handler has the same marking code, but it 
does not run a nested transaction of the same policy at all; that is a separate 
issue (CAMEL-27285, camel-jta).
   
   # 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-27285](https://issues.apache.org/jira/browse/CAMEL-27285).
   
   # 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 the touched modules with 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]

Reply via email to