allthingssecurity opened a new pull request, #30309: URL: https://github.com/apache/camel/pull/30309
# Description [CAMEL-27085](https://issues.apache.org/jira/browse/CAMEL-27085) `DefaultInflightRepository` keeps a counter per route id. `RouteService` adds it when the route is warmed up and removes it when the route is removed, and `RouteInflightRepositoryAdvice` increments and decrements the counter it finds for the route id at that moment. When a route was stopped with a timeout that ran out (a forced stop, `abortAfterTimeout=false`) while an exchange was still in flight, and then removed, its counter (still 1) was dropped. A route added again with the same id (route reload, dev mode, `removeRoute` + `addRoutes`) got a new counter at 0, and when the old exchange ended its advice took the new counter to -1. From then on `size(routeId)` was one less than the real number of exchanges of that route: - the next graceful stop or reload of the route (`DefaultShutdownStrategy` waits while `size(routeId)` plus the pending exchanges is above 0) did not wait for one exchange in flight, which then failed with a `RouteStoppingException`; - `ThrottlingInflightRoutePolicy` with the route scope let one more exchange in; - JMX (`ManagedConsumer`) and the consoles showed -1. Fix, in `DefaultInflightRepository` only (no SPI change): `removeRoute` keeps the counter of a route that still has exchanges in flight, marked as removed. A route added again with the same id uses that counter, so the exchanges of the removed route stay counted until they end (they do run in a route with that id, and `browse(routeId)` lists them too). When the last of them ends and no route took the id again, the counter is dropped. A route removed with nothing in flight is dropped at once, as before. The marking and the drop go through `compute`/`computeIfPresent`, so a route added again while the last old exchange ends keeps its counter. Tests: `InflightRepositoryRouteRemovedWhileInflightTest` holds an exchange in route "slow", stops the route with a 100 ms timeout and removes it: - added again with the same id, then the exchange is released (it fails with `RouteStoppingException`, as for any forced stop): `size("slow")` must be 0 (main: -1), and stays 0 for a new exchange; - added again: while the old exchange runs, `size("slow")` is 1 (main: 0), then 0; - not added again: the counts are 0 after the exchange ended (also on main). Without the change the first two fail. With it the inflight, shutdown strategy, route stop and route remove tests of camel-core pass (71 run, 0 failures), and the new test class passes 20 times in one JVM (60/60). # 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-27085](https://issues.apache.org/jira/browse/CAMEL-27085). # 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; no option, doc or generated file changes. 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. _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]
