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

   In both loops of `RoutingSlip` (`doRoutingSlipWithExpression` and 
`continueRoutingSlip`), the exchange was copied for the next step with 
`prepareExchangeForRoutingSlip` **before** checking whether the step continued 
asynchronously:
   
   ```java
   boolean sync = processExchange(...);
   current = prepareExchangeForRoutingSlip(current, endpoint);
   if (!sync) {
       return ...;
   }
   ```
   
   When the step continues asynchronously, the copy is thrown away: the 
callback continues with the step's own exchange. But another thread may already 
be processing that exchange. The copy then reads its message (headers, body) 
while that thread changes it, and `MessageHelper.resetStreamCache` resets the 
stream cache of the body that the step may be reading. The copy is now made 
only after a step that completed synchronously, so the async path no longer 
touches the exchange. Dynamic Router extends `RoutingSlip`, so it gets the same 
fix.
   
   With the default error handler the step is usually only queued on the same 
thread when this copy runs, so the overlap shows with steps called directly: 
`noErrorHandler`, or inside `doTry`, with a producer that completes on its own 
thread (for example an asynchronous HTTP client).
   
   Found while reviewing #30530 (Routing Slip / Dynamic Router after an 
asynchronous step). The two PRs touch neighbouring lines of 
`continueRoutingSlip`, so the one merged second needs a small rebase.
   
   **Test:** `AsyncEndpointRoutingSlipNoCopyInFlightTest` uses a step that 
continues on its own thread and a `StreamCache` body that counts the resets 
made while the step is in flight. It fails without the fix (`expected: <0> but 
was: <1>`) and passes with it. The existing `*RoutingSlip*` and 
`*DynamicRouter*` tests of camel-core (101) pass.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 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