allthingssecurity opened a new pull request, #30827: URL: https://github.com/apache/camel/pull/30827
# Description [CAMEL-27493](https://issues.apache.org/jira/browse/CAMEL-27493) `IBMEventStreamReloadTriggerTask` is scheduled once (`PeriodTaskScheduler.scheduledTask`): `DefaultPeriodTaskScheduler` submits it to its own thread on the first timer tick and never reads its `Future` again. Its `run()` polls the IBM Event Streams topic in a loop for as long as Camel runs. CAMEL-25702 put a try around the handling of each record, but `kafkaConsumer.poll()` is outside it. So the first exception from `poll()` ended the task: for example the `SaslAuthenticationException` that `KafkaConsumer.poll` throws when the broker rejects the credentials, or an authorization error. The exception went into the `Future` that nobody reads: nothing was logged, every later tick saw the task as running, and no later secret rotation reloaded the CamelContext until a restart. Change, in `run()`: - a failure of `poll()` is caught. The task logs it, waits and polls again with the same consumer (the consumer connects and authenticates again on a later poll, so the loop goes on once the broker accepts the credentials again). The wait starts at 1 second and doubles after each failure in a row, up to 60 seconds. - logging: the first failure in a row at WARN with the exception (`toString()`; stack trace at DEBUG), the repeats at DEBUG, and the first poll that works again at INFO, so a long outage gives one WARN and one INFO. - an `Error` is logged at ERROR and handled the same way; a `VirtualMachineError` is thrown on, as elsewhere in Camel. - the loop still ends when Camel stops: `isRunAllowed()` is checked after a failure, and the wait checks it every 100 ms. It also ends when `doStop` has closed the consumer, and on Kafka's `InterruptException`. The `kafkaConsumer` field, which `doStop` sets to null from another thread, is now `volatile` and read once per poll. - `lastCheckTime` is now set after each poll that did not fail (before, only once when the task started). The "last check" of the secrets dev console therefore stops moving while polls fail. What this does not fix: the consumer keeps the credentials that `doStart` read once (the Event Streams password from the environment or the vault configuration). If that API key is revoked, for example after it was rotated, every poll keeps failing until the application is restarted with the new key, as before, but now with a WARN. Building a new consumer would not help, because it would read the same password. Why not in the scheduler: `DefaultPeriodTaskScheduler` could submit a task again when its `Future` is done, but the Kubernetes secrets and config maps refresh tasks use `scheduledTask` too, and that would change them as well. With this change the IBM loop only ends when Camel stops (or its thread is interrupted), or on a `VirtualMachineError`. Not changed here (separate follow-ups, I will file tickets): - stopping and starting the CamelContext again drops every scheduled vault refresh task (the scheduler clears its listeners on shutdown, and `configureVaultRefresh` runs only once). Low: restarting a stopped context is not recommended. - `doStop` closes the `KafkaConsumer` from the stopping thread while the loop is inside `poll()`, so `close()` fails with "KafkaConsumer is not safe for multi-threaded access" (logged at WARN) and the consumer is never closed. Low, matters in a JVM that keeps running after the context stops. - the Azure Event Hubs refresh task ignores processor errors (`processError` does nothing); I did not check whether the Event Hubs processor can stop by itself. - the same problem in the GCP Pub/Sub task (a failed `Subscriber` is never started again) has its own ticket and PR (CAMEL-27494). Test, in `IBMEventStreamReloadTriggerTaskTest` (package-private, no sleep): `rotationAfterAFailedPollStillTriggersTheReload` uses a consumer whose first poll throws `SaslAuthenticationException` and whose next poll returns the rotation of a watched secret. The reload happens, the task is still running, and the failure is logged at WARN (log4j appender). The three record tests of CAMEL-25702 now share the same helper. The new test fails with the current task (no reload); with the change the unit tests of camel-ibm-secrets-manager pass (36 run, 0 failures) and the test class passes 20 of 20 runs (80 tests). The ITs of the module were not run locally (CI runs them). A TLA+ model of the push-based refresh listeners and the period task scheduler found this: "every rotation is eventually consumed while Camel runs" fails after one exception from `poll()`. The fixed model (catch, back off, poll again) is written but not checked yet. # 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-27493](https://issues.apache.org/jira/browse/CAMEL-27493). # 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 camel-ibm-secrets-manager and the core modules with the formatter and import-sort plugins and ran the module's unit tests. I did not run the full root build. No option or generated file changed.) # 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]
