allthingssecurity opened a new pull request, #26770: URL: https://github.com/apache/camel/pull/26770
# Description [CAMEL-24923](https://issues.apache.org/jira/browse/CAMEL-24923) `loadBalance().weighted(...)` didn't validate the ratio values. Negative ratios, all-zero ratios, or ratios whose sum overflows an `int` let the route start, and then the caller hung: the round robin selection spun forever holding the lock, or `nextInt(0)` threw out of `process()` and the callback was never called. This change: - `WeightedLoadBalancer.doStart` checks the ratios next to the existing count check: none may be negative, at least one must be positive, and the sum must fit in an `int`. A ratio of 0 for some endpoints is still allowed (that endpoint gets no messages). - `QueueLoadBalancer.process` sets an exception thrown by `chooseProcessor` on the exchange and calls the callback, instead of letting it escape the async contract. This also covers a sticky load balancer whose correlation expression throws. - The weighted load balancer docs and the 4.23 upgrade guide mention that such routes now fail at startup. Tests: new `WeightedLoadBalanceInvalidRatioTest`: - `testInvalidRatiosRejectedOnStart`: 7 cases covering both modes. - `testZeroRatioForSomeProcessorsIsAllowed`: guards against over-strict validation. - `testExceptionWhenChoosingProcessorIsSetOnExchange`. Without the fix, 7 cases fail with `Expected java.lang.Exception to be thrown, but nothing was thrown.` and one errors because the exception escapes `process()`. With the fix, all 9 pass. `*LoadBalanc*,Failover*,FailOver*,*Sticky*`: 65 tests, 0 failures. Managed load balancer tests: 8 tests, 0 failures. Found with a Lean 4 model of the weighted load balancers, then reproduced against the real classes. # 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). # 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 and tested the affected modules, including the formatter and import-sort plugins. 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 commit carries a `Co-Authored-By` trailer. -- 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]
