vignesh-manel opened a new pull request, #28574:
URL: https://github.com/apache/camel/pull/28574

   # Description
   
   https://issues.apache.org/jira/browse/CAMEL-26313
   
   ## Problem
   
   When the circuit opens, `ThrottlingExceptionRoutePolicy` suspends the 
route's consumer and schedules the half open timer with the value 
`halfOpenAfter` has at that moment (`addHalfOpenTimer`). `halfOpenAfter` can be 
changed at runtime with `setHalfOpenAfter`, which 
`ManagedThrottlingExceptionRoutePolicy` exposes over JMX.
   
   If it is raised while the circuit is open, the timer fires before the new 
value. `calculateState` then takes the "Keeping circuit open (time not 
elapsed)" branch, which scheduled nothing. The consumer is suspended, so no 
exchange comes to call `calculateState` again, and the route stays suspended 
until it is restarted.
   
   ## Change
   
   - In the "time not elapsed" branch, the half open timer is scheduled again 
for the time that is left (`halfOpenAfter - elapsed`), as the ticket proposes. 
I chose this over calling `addHalfOpenTimer(route)` with the full 
`halfOpenAfter`, because this branch is also reached when an exchange that was 
still in flight finishes after the circuit opened. With the time that is left, 
the replacement timer is due at the same moment as the one it replaces, so the 
half open check is not pushed back.
   - `halfOpenAfter` is read once in that block. If the value were lowered 
concurrently between the check and the scheduling, a second read could give a 
negative delay, which `Timer.schedule` rejects.
   - `addHalfOpenTimer(Route)` keeps its signature and delegates to a new 
private `addHalfOpenTimer(Route, long delay)`. No class in the repository 
overrides `addHalfOpenTimer`.
   - New `ThrottlingExceptionRoutePolicyRaiseHalfOpenAfterTest`, using 
Awaitility as the other policy tests do. With `halfOpenAfter=2000`, it opens 
the circuit, raises `halfOpenAfter` to 3000, and checks that the consumer is 
resumed and the next exchange is processed.
   
   No doc or upgrade-guide change: the documented behaviour (half open after 
`halfOpenAfter`) is unchanged, and this makes it hold after a runtime change.
   
   ## Verification (local, JDK 21.0.12.1, Maven 3.9.12)
   
   - Before the fix, the new test failed: the consumer was still suspended 
after 10 seconds (`ConditionTimeoutException` at the wait for 
`consumer::isStarted`).
   - After the fix it passes in about 3.5 s, which is consistent with half 
opening at the raised 3000 ms rather than at 2000 ms. The test does not assert 
that timing.
   - All 10 `ThrottlingExceptionRoutePolicy*Test` classes in camel-core pass 
(15 tests), as do `ManagedThrottlingExceptionRoutePolicyTest` 
(camel-management) and `CircuitBreakerDevConsoleTest` (camel-console).
   - `mvn install -Psourcecheck` passes in `core/camel-support` and 
`core/camel-core`, with no uncommitted changes afterwards.
   - I have not run the full build or the full camel-core suite; this is a 
draft until CI is green.
   
   # 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.
     _Not from the root: I ran `mvn install -Psourcecheck` in 
`core/camel-support` and `core/camel-core`. Nothing was generated or changed. 
CI's uncommitted-changes check covers the rest._
   
   # 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.
   
   _Claude Code on behalf of vignesh-manel_
   
   🤖 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