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

   _Claude Code on behalf of davsclaus_
   
   ## Summary
   
   Fix race condition in `camel-cxf-soap` (`CxfConsumer`) and `camel-cxf-rest` 
(`CxfRsInvoker`) where a CXF continuation timeout fires while the Camel async 
processor is still running, leading to:
   
   1. **Double `continuation.resume()`** — the `done()` callback 
unconditionally called `resume()` even after timeout already produced a response
   2. **Double UoW close** — `UnitOfWorkCloserInterceptor` closes UoW on the 
timeout response path, then the late callback's resume triggers a second close. 
`DefaultUnitOfWork.done()` is not idempotent — a double-call fires 
synchronization callbacks twice, double-removes from inflight registry, and 
with pooled exchanges recycles the Exchange while the worker still holds it
   3. **Concurrent Exchange mutation** — timeout thread sets 
`ExchangeTimedOutException` on the same Exchange the async worker is still 
processing
   
   ### Fix
   
   Introduce an `AtomicBoolean completed` per-request so exactly one of 
{timeout, async completion} wins the response and UoW lifecycle:
   
   - **`done()` callback**: guard `continuation.resume()` with 
`completed.compareAndSet(false, true)`. If timeout already won, the callback 
closes the UoW (safely, since the worker has finished)
   - **Timeout branch**: guard with the same `compareAndSet`. If won, write the 
timeout response and detach the Camel Exchange from the CXF exchange so 
`UnitOfWorkCloserInterceptor` won't close UoW prematurely. The late `done()` 
callback closes it after the worker finishes
   
   ### Files changed
   
   - `CxfRsInvoker.java` — REST async invoke race guard
   - `CxfConsumer.java` — SOAP async invoke race guard (symmetric change)
   - `CxfConsumerContinuationTimeoutTest.java` — add test verifying timeout 
followed by normal request (no state corruption)
   
   ## Test plan
   
   - [x] `CxfConsumerContinuationTimeoutTest` — all 3 tests pass (no-timeout, 
timeout, timeout-then-normal)
   - [x] Full `camel-cxf-soap` module test suite passes (161 tests)
   - [x] Full `camel-cxf-rest` module test suite passes
   - [x] Full root build (`mvn clean install -DskipTests`) passes with no 
regenerated file changes
   
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   Co-Authored-By: Claude Opus 4.6 <[email protected]>


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