davsclaus opened a new pull request, #30867: URL: https://github.com/apache/camel/pull/30867
# Description [CAMEL-27496](https://issues.apache.org/jira/browse/CAMEL-27496): a subscriber loop of the `google-pubsub` consumer could end while the consumer was started, and nothing started it again. The route stayed Started and its health check UP, and the consumer received nothing until the route was restarted: - synchronous pull: a non-retryable error (`PERMISSION_DENIED` while an IAM binding is changed, `NOT_FOUND` while the subscription is created again) was thrown on, and `run()` only logged it; - asynchronous pull: a `Subscriber` that failed with a non-retryable error ended the loop on purpose (`break`); - asynchronous pull: an `IOException` of `getSubscriber` (credentials that cannot be loaded at that moment) was outside the `try`; - an `Error` (`NoClassDefFoundError` of client libraries that do not match): `run()` caught `Exception` only, in a `Future` nobody reads, so not even a log line. ## Fix Builds on the retry delay of CAMEL-27495 (#30829). - A failed attempt (`Exception` or `Error`) ends the subscription or the pull, not the loop. It is logged (the first one in a row at ERROR with the stack trace, the next ones in one WARN line), given to the `ExceptionHandler` with `bridgeErrorHandler`, and the loop subscribes or pulls again after the retry delay (5 s, counted from the start of the failed attempt). The asynchronous loop now uses `waitBeforeRetry` too, so a stop ends its retry delay at once. - The failure of an asynchronous `Subscriber` is reported instead of the `IllegalStateException` that wraps it. After failed attempts, a `Subscriber` only counts as working once it has run for the retry delay, as it is running before its streaming pull is answered (a missing subscription fails it right after the start). - A `VirtualMachineError` stops the consumer until the route is restarted (`isStopOnFatalError` / `handleFatalError` of CAMEL-27515), and also ends the subscribers, pulls and retry delays of the other loops. The ticket said to throw it on, but CAMEL-27515 is now the rule for consumers that pull in a loop, and throwing it into a `Future` nobody reads would only end that one loop, silently. - New `GooglePubsubConsumerHealthCheck` (readiness only): DOWN with the failure (details `failing.loops`, `failed.attempts`) while a loop of the current start waits to subscribe or pull again or has ended for good, and after a fatal error. - Upgrade guide entry and a paragraph in the component docs. Behaviour changes worth a look: - with `bridgeErrorHandler=true`, every failed attempt of the synchronous pull now reaches the error handler of the route (at most once per retry delay per loop); before, only failures of the asynchronous pull were bridged; - the log messages of the failures changed ("Failure getting messages from PubSub <subscription>. Pulling again within 5s." / "Subscribing again ..."). ## Tests `GooglePubsubConsumerLoopRestartTest` (6 tests, stubs, no sleeps): synchronous `PERMISSION_DENIED` then a message, `NoClassDefFoundError` from `getSubscriberStub`, asynchronous `IOException` from `getSubscriber` then `NOT_FOUND` right after the start then a working subscriber (with the bridged error), a stop during a retry delay, `OutOfMemoryError`, and the health check. The whole module (1067 tests, with the DST test of CAMEL-27495) passes with `-Dcamel.surefire.forkCount=4`. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 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]
