allthingssecurity opened a new pull request, #30244: URL: https://github.com/apache/camel/pull/30244
# Description [CAMEL-27038](https://issues.apache.org/jira/browse/CAMEL-27038) Found while building the zookeeper-master DST world of #30137 (CAMEL-26974): a route whose endpoint failed to create its consumer could not be started again. Reproduced here with a plain unit test, outside the DST harness. When a stopped route is started, `RouteService.setUp` sets `setUpDone` and then runs `doSetup`, which calls `endpoint.createConsumer` (through `DefaultRoute.initializeServices`). When `createConsumer` throws, the start fails with `FailedToStartRouteException`, as it should, but `setUpDone` stays `true`, while the route service has no consumer and no child services (the stop of the route cleared both). So: - the next start skips the set up, and the warm up fails in `startChildServices` with `NullPointerException: Cannot invoke "java.util.List.iterator()" because "services" is null`. `warmUpDone` is set before that work, so it stays `true` as well; - the start after that skips both, finds no consumer, and starts the route service: the route reports `Started`, but nothing consumes it. The route could only be started again after it was removed and added again. `RouteController.startRoute` says it starts "the given route if it has been previously stopped", and throws if the route could not be started; a start that failed leaves the route stopped, so a later start, once the endpoint can create the consumer again, should set it up and start it. Change, in `RouteService.setUp`: when `doSetup` throws, the consumer and the child services it found are cleared and `setUpDone` is set back to `false` (under the lock of the route service, which `doSetup` holds as well), so the next start sets the route up again and creates the consumer. Nothing changes when the set up succeeds. Test, new `RouteStartAfterFailedCreateConsumerTest` (a direct endpoint whose `createConsumer` throws while a flag is set; the route is stopped, the start fails, the flag is cleared and the route started again): - `routeStartsOnceTheConsumerCanBeCreated`: the second start succeeds and the route consumes; - `routeStartsAfterTwoFailedStarts`: after two failed starts, the third start succeeds and the route consumes. Without the change both fail on main: the first with the `NullPointerException` above, the second with `DirectConsumerNotAvailableException` from a route that reports `Started`. With it both pass, and the camel-core tests pass (9433 run, 0 failures, 45 skipped; 12 errors that are not related: 11 `DumpModel*` tests with a `NoClassDefFoundError` of `OgnlExpression` from a stale camel-yaml-io jar in my local repository, and `ValidatorExternalResourceTest`, which needs network access to raw.githubusercontent.com). I also checked the warm up the same way (a processor of the route whose start fails once, then the route is started again): it starts and routes on main, so it is not changed here. No documentation or upgrade guide change: a route that failed to start can now be started again, as documented. Backport: camel-4.18.x has the same `setUp` (with `e.getLocalizedMessage()` instead of `extractUsefulMessage` of CAMEL-24301); the same three lines apply there by hand. # 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-27038](https://issues.apache.org/jira/browse/CAMEL-27038). # 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 the core modules with the formatter and import-sort plugins and ran the camel-core tests. I did not run the full root build.) # 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 commits carry 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]
