Croway opened a new pull request, #30739: URL: https://github.com/apache/camel/pull/30739
[CAMEL-27515](https://issues.apache.org/jira/browse/CAMEL-27515): a `VirtualMachineError` (`OutOfMemoryError`, `StackOverflowError`, `InternalError`) thrown in a route now fails its exchange, and Camel does not recover from it on its own. A consumer that pulls work in a loop stops until its route is restarted. Agreed for 4.24.0 on the ticket. ## Why Today the step calls its callback and then throws the `Error` on, with no exception on the exchange: - the rest of the route runs later, on the next exchange of the same thread, as if the step had succeeded (4.18.5, 4.23.0); - on main, a route with a dead letter channel, redelivery or `onException` goes on at once and the caller gets success (since CAMEL-26446, not released). In a Camel Main app with platform-http, a `POST /orders` whose pricing overflows the stack returns HTTP 200 "created" and saves the half-built order; - a request-reply through `threads()` gets a success reply built from the failed request, or never answers; - a consumer loop ends silently (polling task, seda thread, every route on a shared timer), with the route still Started and its health check UP. ## What changes - **The exchange fails** with the `Error` at every route step that had the CAMEL-26741 carve-out (`DelegateSyncProcessor`, `AsyncProcessorConverterHelper`, the bean adapters, the EIPs, the advices). Nothing of the route runs later. The caller gets the failure, the failure synchronizations run, and the `ExchangeFailedEvent` carries the `Error`. - **No implicit recovery**: no redelivery, no dead letter channel, no circuit breaker fallback (Resilience4j, Fault Tolerance), no failover of a load balancer, no split error threshold. A `VirtualMachineError` of a dead letter route fails the exchange too. - **An explicit catch still works, as in Java**: an `onException` or `doCatch` that names it or a supertype (`Throwable`, `Error`, `VirtualMachineError`, its own class) handles it, without the redelivery or the dead letter channel of the error handler. `onException(Exception.class)` and `doCatch(Exception.class)` do not match it. `doFinally` and `onCompletion` run as for any failure. - **Logged once at ERROR** by the error handler, with the route and node. - **Consumers that pull work in a loop stop** after an unhandled `VirtualMachineError`, from their route or from their own loop: `DefaultConsumer.getFatalError()`, the opt-in `isStopOnFatalError()`, `handleFatalError()`; `isRunAllowed()` is false until the route is restarted, and `ConsumerHealthCheck` reports DOWN. Opted in: `ScheduledPollConsumer` (all polling consumers), timer, seda, hazelcast seda and queue (poll mode). The aws2-sqs visibility extender stops the consumer on such an error, and survives other errors instead of ending silently. Push consumers (HTTP, direct) only fail the request. - A polling consumer whose poll throws another `Error` (such as a `NoClassDefFoundError` of a client library) treats it as a failed poll and polls again. - Restarting a route, a pod or the JVM is left to the application or the platform. `error-handler.adoc` shows how to log and shut down gracefully with an event notifier. ## Not in this PR - Background tasks still throw such an error on: the aggregator's background tasks, `DefaultTimeoutMap`, `BackgroundTask`, `TimerListenerManager`, on-completion synchronizations, jgroups-raft, and the supervising route controller (CAMEL-27472). - camel-kafka and camel-kafka-share fail the record as for another error, and their own loop terminates visibly on such an error, but they do not opt in to the consumer stop yet: stopping without committing the failed record needs broker tests. - Edge cases left for a follow-up: a `rollbackOnlyLast` transaction, a `VirtualMachineError` thrown by `doFinally`, a late failure after a route restart, seda with `multipleConsumers` (and a second `concurrentConsumers` worker that may route one more message it was already waiting for), the health check of a manually started route, a multicast whose later copy fails with an ordinary exception (the default aggregation keeps the later one), and the choice between two explicit clauses when the error has a `Throwable` cause. This also covers the consumer parts of CAMEL-27471 (seda), CAMEL-27473 (aws2-sqs extender), CAMEL-27474 (hazelcast) and CAMEL-27487 / #30694 (`ScheduledPollConsumer`), under the umbrella CAMEL-27469. ## Tests - `VirtualMachineErrorRecoveryTest`: no match through the cause of the error, no inherited redelivery or dead letter channel for an explicit clause, a dead letter route (also when the original failure is handled), failover, split thresholds (the original message is kept), `onExceptionOccurred`. - `ConsumerStopsAfterVirtualMachineErrorTest`: seda and file consumers stop and report DOWN, a restart brings them back, an explicit catch keeps the consumer going. `VirtualMachineErrorEventTest`: the event carries the error. - `ProcessorThrowsErrorTest` and the other tests of the carve-out now check the new contract; timer, aws2-sqs, Resilience4j and Fault Tolerance tests. - The full camel-core suite (9,810 tests) passes, apart from one or two timing-sensitive tests per run that pass when re-run (file tests that also fail randomly on main, `MockEndpointTimeClauseTest`). The new and changed test classes passed 305 runs out of 305. - Checked in real applications (Spring Boot + Tomcat, Camel Main + platform-http + the timer-source Kamelet) on 4.23.0, main and this branch. ## Docs - `error-handler.adoc`: the rule, and the event notifier recipe. - 4.24 upgrade guide: a new entry with each change compared with 4.23, and the camel-bean entry rewritten. _Claude Code on behalf of Croway_ -- 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]
