Federico Mariani created CAMEL-27469:
----------------------------------------
Summary: 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
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)