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

   # Description
   
   [CAMEL-27438](https://issues.apache.org/jira/browse/CAMEL-27438)
   
   `ThrottlingExceptionRoutePolicy` schedules one half open check when it opens 
the circuit, on the scheduler of the policy (CAMEL-26104). When that check half 
opened the circuit and resuming the consumer threw, the exception went to the 
exception handler of the policy and the circuit stayed open. But the check that 
just ran was the only one scheduled, and the consumer is suspended, so no 
exchange completes and checks the circuit either. Nothing checked the circuit 
again: it stayed open, and the route took no message until it was restarted, 
although the docs say that the circuit closes by itself.
   
   The same happened with a `halfOpenHandler`: when a ready handler closes the 
circuit and the resume throws, and when a handler that is not ready keeps the 
circuit open and suspending the consumer again throws. When the handler itself 
throws, the policy already checks again after `halfOpenAfter`, and CAMEL-26313 
made the check schedule the next one when `halfOpenAfter` was raised, so a 
retry is the intended behaviour.
   
   Change: the half open task remembers the future of its check. When the check 
ends (in a `finally`) with the circuit still open and no other check scheduled 
since, it logs one WARN naming the route and schedules the next check after 
`halfOpenAfter`. The exception still goes to the exception handler. A check of 
a removed route or a stopped policy schedules nothing, as before (the scheduler 
check at the start of the task, and `addHalfOpenTimer` skips a stopped policy). 
Every path that keeps the circuit open on purpose (time not elapsed yet, 
`keepOpen`, a handler that is not ready) already schedules the next check, so 
it is not touched.
   
   Not changed: when the `doResume` of a real consumer throws, the consumer is 
left failed, and resuming it again does nothing, so the next check half opens 
the circuit without bringing the consumer back. That still needs the route 
restarted, as on main; the retry helps when the resume fails before the 
consumer does (for example in an override of `resumeOrStartConsumer`) or when 
the error is transient.
   
   Model: the TLA+ model of the policy, its half open timer and the inflight 
policy, with one suspend or resume that throws. On main, "an open circuit 
always has a half open check pending" is violated (and "an open circuit does 
not stay open" too). With the change both hold (3 threads, 741,242 distinct 
states, exhaustive), also together with the change that makes the throttling 
policies of a route wait for each other before resuming the consumer (814,186 
states).
   
   Tests: new `ThrottlingExceptionRoutePolicyHalfOpenCheckFailureTest` 
(package-private, JUnit assertions as the module), with `halfOpenAfter=100` and 
a policy whose first resume (or second suspend) throws. Right after the failing 
exchange the tests check that the consumer was suspended once (a counter), not 
the state of the circuit, as the first check may already have run 100 millis 
later on a slow machine:
   
   - `halfOpenCheckIsRepeatedWhenResumingTheConsumerFails`: the next check half 
opens the circuit and resumes the consumer.
   - `halfOpenCheckIsRepeatedWhenResumingTheConsumerFailsWhileClosing`: a ready 
`halfOpenHandler`; the next check closes the circuit.
   - `halfOpenCheckIsRepeatedWhenSuspendingTheConsumerFailsWhileKeepingItOpen`: 
a `halfOpenHandler` that is not ready; the circuit is still checked afterwards.
   
   All three fail on main (the circuit is never checked again). With the 
change: the camel-core and camel-support tests matching `*RoutePolicy*`, 
`*Throttling*`, `*Throttle*` and `*SupervisingRouteController*` pass 
(camel-core 164, camel-support 3, 0 failures); the new class 20 times in one 
JVM, 60 runs, 0 failures. Formatter and import-sort checks pass.
   
   A second change for the same policy (the throttling policies of a route 
resume the consumer only when no other policy keeps it suspended) also edits 
`ThrottlingExceptionRoutePolicy`, in `halfOpenCircuit` and `closeCircuit`, not 
in the half open task. The two do not overlap and merge cleanly in either order.
   
   # 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-27438](https://issues.apache.org/jira/browse/CAMEL-27438).
   
   # 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 camel-support and camel-core, including the formatter 
and import-sort plugins. No option changed. 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]

Reply via email to