gnodet opened a new pull request, #29257: URL: https://github.com/apache/camel/pull/29257
## Summary Fix `StreamCachingAdvice` execution order to prevent `"Cannot reset stream from file"` when route-level stream caching uses spooled (file-backed) stream caches. ## Root Cause `StreamCachingAdvice.getOrder()` returned `Ordered.HIGHEST` (`Integer.MIN_VALUE`), making it sort first in the advice list. `CamelInternalProcessor` runs `after()` callbacks in **reverse** sorted order. So `UnitOfWorkProcessorAdvice.after()` (order = 0, the default) executed **before** `StreamCachingAdvice.after()` (HIGHEST, so last in reverse order). `UnitOfWorkProcessorAdvice.after()` calls `doneUow()`, which triggers `TempFileManager`'s `onCompletion` listener. That listener closes and deletes the spooled temporary file. Then `StreamCachingAdvice.after()` calls `MessageHelper.resetStreamCache()`, which calls `FileInputStreamCache.reset()` on the now-deleted file, throwing: ``` Cannot reset stream from file <path> ``` The exchange was then failed with this error, even though processing had completed successfully. ## Fix Change `StreamCachingAdvice.getOrder()` from `Ordered.HIGHEST` to `Ordered.LOWEST`. This ensures: - **`after()` direction** (reverse order): `StreamCachingAdvice.after()` runs **first** (before UoW teardown), so the stream reset happens while the spool file still exists. ✓ - **`before()` direction**: `StreamCachingAdvice.before()` now runs after the UoW advice, which is actually slightly better (UoW is initialized before stream caching converts the body) and does not break any existing behavior. `InstrumentationProcessor` has order `LOWEST - 2`, so `StreamCachingAdvice` at `LOWEST` still runs before it in `before()`. ## Tests Added `RouteStreamCachingSpoolAdviceOrderTest` with two tests: 1. Single exchange: sends a 32 KB stream (above the 1 KB spool threshold), verifies the exchange completes without error and the body is intact. 2. Multiple exchanges: sends 5 spooled streams sequentially, verifies all complete successfully. Both tests reproduce the bug without the fix (exchange fails with `RuntimeCamelException: Cannot reset stream from file`) and pass with the fix. Fixes https://issues.apache.org/jira/browse/CAMEL-26640 _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_ -- 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]
