allthingssecurity opened a new pull request, #28468:
URL: https://github.com/apache/camel/pull/28468

   # Description
   
   [CAMEL-26292](https://issues.apache.org/jira/browse/CAMEL-26292)
   
   With `scope=Context`, `ThrottlingInflightRoutePolicy` throttles from an 
event notifier, which per the class javadoc listens "for events when Exchanges 
is done". The notifier only took `ExchangeCompletedEvent`. An exchange that is 
done with an exception raises `ExchangeFailedEvent` instead 
(`DefaultUnitOfWork.done`), so failed exchanges never reached `throttle()`, 
while the route scope throttles every done exchange in `onExchangeDone`.
   
   The policy suspends the consumer when an exchange completes while too many 
are inflight, and only a later done exchange resumes it. When the exchanges 
still inflight all fail (a backend outage, which is when exchanges pile up), 
the consumer stays suspended for good: the route consumes nothing more, also 
after the backend recovers, until another exchange of the context completes (in 
another route, or one sent by a `ProducerTemplate`) or the route is restarted.
   
   Changes:
   - `ContextScopedEventNotifier.isEnabled` takes `ExchangeCompletedEvent` and 
`ExchangeFailedEvent`; `notify` reads the exchange through `ExchangeEvent`.
   - `DefaultUnitOfWork.done` raises exactly one of the two events for an 
exchange (`isFailed()` picks it), after removing the exchange from the inflight 
repository, so no exchange is throttled twice. `ExchangeFailureHandledEvent` is 
raised while the exchange is still inflight, and a handled exchange then raises 
`ExchangeCompletedEvent`, so it is not needed.
   - Like with the route scope, a failed exchange now also suspends the 
consumer when too many exchanges are inflight.
   - No option change, and no change for the route scope.
   - Backport: camel-4.22.x, 4.18.x and 4.14.x have the same code (read, not 
run); the commit cherry-picks onto 4.22.x and 4.18.x without conflict.
   
   Tests:
   - New `ThrottlingInflightRoutePolicyContextScopeFailedExchangesTest` 
(camel-core; latches, no sleeps): three exchanges enter a `seda` route with 
`concurrentConsumers=3`, `maxInflightExchanges=1`; one completes and the policy 
suspends the consumer; the two others fail. On main the consumer is still 
suspended after both failures (3 of 3 runs); with the fix it is resumed and a 
fourth message is consumed. There was no test of the context scope before.
   - camel-support: 140 tests, 0 failures. camel-core, the `*Throttl*`, 
`*RoutePolicy*` and `org.apache.camel.support` tests: 612 tests, 1 failure, 
`RouteWatcherReloadChangedRoutesTest.theSummarySaysWhichRoutesTheReloadChanged`,
 which fails the same way on an unchanged origin/main in this offline 
environment. camel-management `*Throttl*` and `*RoutePolicy*` tests: 12 tests, 
0 failures. The formatter and import-sort plugins ran.
   
   How it was found: a JVM model in Rocq that executes the real class files. 
The kernel-checked theorem `context_scope_ignores_failed_exchanges` runs the 
compiled `ContextScopedEventNotifier.isEnabled` of main on an 
`ExchangeCompletedEvent` and an `ExchangeFailedEvent` and gets `true` and 
`false`; `fix_context_scope_sees_failed_exchanges` gets `true` for both with 
this change. HotSpot gives the same answers on the same class files, and the 
route-level effect is the test above.
   
   # 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-26292) 
filed for the change (usually before you start working on it): 
[CAMEL-26292](https://issues.apache.org/jira/browse/CAMEL-26292).
   
   # 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 and ran the tests above, including the formatter 
and import-sort plugins. No 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]

Reply via email to