[
https://issues.apache.org/jira/browse/CAMEL-27469?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150240#comment-18150240
]
Federico Mariani commented on CAMEL-27469:
------------------------------------------
[~gnodet] thanks for picking up the sub-tasks. Before more fixes land, could we
agree on one rule for a {{VirtualMachineError}} ({{OutOfMemoryError}},
{{StackOverflowError}})? The fixes so far handle it differently:
* CAMEL-27487 ({{ScheduledPollConsumer}}, PR #30694): the task ends, and the
health check stays DOWN until the route is restarted.
* CAMEL-27470 (camel-timer, PR #30713): the timer task of the route is
cancelled, and an ERROR is logged.
* CAMEL-27471 (camel-seda), as planned in its comment: log the Error and go on
with the next exchange, also after a {{VirtualMachineError}}.
* Already merged: camel-kafka (CAMEL-27298) ends the task with the health check
DOWN, and camel-cli-connector (CAMEL-26794) goes on after any {{Throwable}}.
My suggestion:
* An Error that is not a {{VirtualMachineError}} is handled like an exception,
and the loop goes on. Since CAMEL-26741, such an Error thrown by a processor
already fails the exchange, so it reaches the loop only from the code of the
consumer or of its client library.
* A {{VirtualMachineError}} ends the loop of this consumer only, never a thread
or a timer that other routes share. It is logged at ERROR with a message saying
that the route must be restarted, and the health check of the consumer, if it
has one, is DOWN until then. This matches CAMEL-21769 (the JVM may be in an
unknown state) and CAMEL-27487.
Two facts that matter for the fixes:
* A {{VirtualMachineError}} thrown by the route leaves the exchange inflight.
Stopping or restarting the route then waits for the shutdown timeout (10 s by
default). I reproduced this with the negative-delay path of PR #30713.
* These bugs predate CAMEL-26741. On 4.23.0, a {{StackOverflowError}} in a
timer route also stops every route on the same timer. So they are not 4.24
regressions.
_Claude Code on behalf of Croway_
> Consumers - a consumer loop or background task stops for good after a
> java.lang.Error, and nothing shows it
> -----------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27469
> URL: https://issues.apache.org/jira/browse/CAMEL-27469
> Project: Camel
> Issue Type: Improvement
> Components: camel-core
> Reporter: Federico Mariani
> Priority: Major
>
> A consumer that runs its loop, or a task it depends on, on an executor or a
> thread of its own, and catches only {{Exception}} there, stops for good when
> a {{java.lang.Error}} is thrown in it:
> * a periodic task of a {{ScheduledExecutorService}} is not run again, and the
> executor keeps the Error in a {{Future}} that nothing reads;
> * a thread, or a {{java.util.Timer}}, ends.
> The route still says Started, the health check of the consumer (if it has
> one) stays UP, and often nothing is logged.
> Errors that get there:
> * an Error of the consumer's own code or of its client library: a
> {{NoClassDefFoundError}}, an {{ExceptionInInitializerError}} of a class that
> cannot be initialized (such as a class of a message being deserialized), an
> {{OutOfMemoryError}} thrown by library code. CAMEL-26741 does not cover them,
> as no processor throws them;
> * a {{VirtualMachineError}} ({{OutOfMemoryError}}, {{StackOverflowError}})
> thrown in the route, which CAMEL-26741 throws on to the caller on purpose.
> The same has been fixed for camel-kafka (CAMEL-27298), camel-kafka-share
> (CAMEL-27305), {{TimerListenerManager}} (CAMEL-26906), camel-cli-connector
> (CAMEL-26794) and {{BackgroundTask}} (CAMEL-26909), and is in progress for
> camel-aws2-kinesis (CAMEL-27459) and camel-sjms (CAMEL-27435). These fixes do
> not treat a {{VirtualMachineError}} the same way: camel-kafka and
> {{TimerListenerManager}} let it end the task, camel-cli-connector keeps going
> after any {{Throwable}}.
> h3. Proposal
> A consumer loop never ends silently:
> * an Error that is not a {{VirtualMachineError}} is handled as an exception:
> it is logged (or given to the exception handler of the consumer), and the
> loop goes on;
> * a {{VirtualMachineError}} may end the loop, but then it is logged at ERROR,
> saying what stopped and that the route must be restarted, and the health
> check of the consumer (if it has one) reports DOWN.
> h3. Polling consumers
> {{ScheduledPollConsumer}} (all the polling consumers, such as camel-aws2-s3,
> camel-file, camel-ftp and camel-aws2-sqs) has the same problem since
> CAMEL-21769: {{run()}} logs the Error and throws it on, so the scheduled task
> ends, while {{isSchedulerStarted()}} stays true and the health check UP. A
> Camel user who found it with camel-aws2-s3 will open an issue with a fix, so
> it is not a sub-task of this one.
> h3. Sub-tasks
> Each sub-task has been reproduced on main with a test.
> h3. Not reproduced yet
> Found by reading the code only, to check before opening a sub-task:
> * camel-zookeeper-master: the start of the delegate consumer in
> {{MasterConsumer}}, and the group thread of {{ZooKeeperGroup}}
> * camel-kubernetes: the leader election ({{KubernetesLeadershipController}}),
> and the watch of the consumers ({{KubernetesHelper}})
> * camel-disruptor: no exception handler is set on the Disruptor
> * the loops of camel-pulsar with {{messageListener=false}}, the camel-nats
> JetStream pull consumer, camel-zookeeper, camel-mongodb (tailable cursor and
> change streams), camel-iggy, camel-file-watch, the camel-google-pubsub
> synchronous pull, camel-mtconnect
> * background tasks: the changelog poller of the camel-kafka
> {{KafkaIdempotentRepository}}, the keep-alive of the camel-sql
> {{JdbcOrphanLockAwareIdempotentRepository}}, the session check of camel-jcr,
> the connection monitor of camel-xmpp, the timer of the camel-dns
> {{DnsActivationPolicy}}, the accept thread of camel-as2, the leadership
> refresh of camel-infinispan, the reconnect of camel-milo
> _Claude Code on behalf of Croway_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)