allthingssecurity opened a new pull request, #29899: URL: https://github.com/apache/camel/pull/29899
# Description [CAMEL-26908](https://issues.apache.org/jira/browse/CAMEL-26908) Follow-up of #29525 (CAMEL-26741, an `Error` of a processor fails the exchange): another place that catches only `Exception`, found while going through the follow-ups of that change. `UnitOfWorkHelper` (camel-support) runs the on completions (`Synchronization`) of an exchange when its unit of work is done, and their route aware callbacks (`SynchronizationRouteAware.onBeforeRoute` / `onAfterRoute`) when the exchange enters or leaves a route. It caught only `Exception` around each call, "to ensure all synchronizations have a chance to run", and logged it at WARN. An `Error` that is not a `VirtualMachineError` (such as a `NoClassDefFoundError` of a client library, or an `AssertionError`) thrown by one of them escaped instead: - the on completions after it did not run, such as the commit or rollback of the consumer (the move of a file, the acknowledge of a message) or the release of a resource; - `DefaultUnitOfWork.done` stopped before it removed the exchange from the inflight registry, fired the completed or failed event and released a pooled exchange, and `UnitOfWorkHelper.doneUow`, which also caught only `Exception`, let the `Error` through to the caller (the sender or the consumer got the `Error`), so the exchange stayed in the inflight registry; - an `Error` of `onBeforeRoute` or `onAfterRoute` also skipped the end of the route: its inflight count (so a graceful shutdown waited for its timeout), its route policies, and, in the route that created the unit of work, the unit of work itself, so none of the on completions ran. Change: `doneSynchronization`, the `onBeforeRoute` and `onAfterRoute` loops and `doneUow` also catch such an `Error`, log it as they log an exception, and go on. A `VirtualMachineError` is thrown on as before. The same helper runs the on completions that other code hands over and completes itself (the aggregator, `enrich`/`pollEnrich`, the onCompletion EIP, `seda`, `disruptor`, `stub`, `google-pubsub` and `ConsumerTemplate.doneUoW`); they get the same behaviour, and none of them relied on the `Error` being thrown on (in the synchronous pull of `google-pubsub`, it ended the pull loop). `EventHelper` already catches `Throwable` around `isEnabled` and `notify` of each event notifier, so the events were not part of this. Not changed here: an `Error` of a `RoutePolicy` (`onExchangeBegin` / `onExchangeDone`) or of another advice of the route still skips the end of the unit of work (`RoutePolicyAdvice`, `AdviceIterator.runAfterTask`, the loop over the advices in `CamelInternalProcessor`): that is the separate PR of CAMEL-26907 (the advices of a route, its route policies and the result processor of a `ProducerTemplate` send), which changes other files. The event and pooled-exchange catches of `DefaultUnitOfWork.done` and `DefaultConsumerTemplate.doneUoW` are left as they are (Camel code, no user callback). Tests, new `SynchronizationThrowsErrorTest` (camel-core; each send is bounded to 10 seconds; two on completions are added to the exchange, the one that fails runs first, and the test checks that the other one ran and that nothing stays inflight): - `onComplete` throws an `AssertionError`; - `onFailure` throws an `AssertionError` (the route throws an exception, which the exchange keeps); - the route aware callbacks throw an `AssertionError` when the exchange enters and leaves a second route, and leaves the first (the exact order of the calls is checked); - a control: `onComplete` throws an `IllegalStateException` (logged and ignored before too); - `SplitterShareUnitOfWorkTest` asserted inside `onDone`; it now records the counts there and asserts them after the send, as an assertion there no longer fails the test; - new `UnitOfWorkDoneThrowsErrorTest`: a custom unit of work (a `UnitOfWorkFactory` plugin) whose `done` throws an `AssertionError`: the send returns the exchange without an exception (`doneUow`). Without the change the four `Error` tests fail on main (the `Error` reaches the caller of the send); the control passes. With it they pass, the on completion and unit of work tests of camel-core pass (190 run, 0 failures, 3 skipped), 20 runs of the two new classes in one JVM pass (100/100), and the camel-core tests pass (9220 run with the production change, 0 failures; 11 errors, all `DumpModelAsYaml*`/`DumpModel*` tests that fail with `NoClassDefFoundError: OgnlExpression` from a stale camel-yaml-io jar in my local repository, unrelated). Upgrade guide: a 4.24 section "an Error of an on completion is logged, and the other on completions run", as the caller no longer gets such an `Error` (an assertion inside an on completion no longer fails the caller), next to the section of CAMEL-26866. Nothing changes for an exception or a `VirtualMachineError`. # 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-26908](https://issues.apache.org/jira/browse/CAMEL-26908). # 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 core modules with the formatter and import-sort plugins and ran the camel-core tests. 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]
