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

   # Description
   
   [CAMEL-24926](https://issues.apache.org/jira/browse/CAMEL-24926)
   
   With `throttle(n).concurrentRequestsMode()`, returning a permit schedules 
`clean()` 10 s later, and `clean()` removed the throttling state even if a 
permit had been taken in the meantime. The next exchange then created a new 
state with all permits, so more than `n` exchanges could be inside the 
throttled part at once, whenever one exchange held its permit for more than 10 
s.
   
   This change:
   - `clean()` only removes the state when all permits are available and nobody 
is waiting. The check and a `removed` mark are done under the state lock 
(`states.computeIfPresent`).
   - An exchange that took a permit from a state that was removed right after 
it looked the state up gives the permit back and takes one from the current 
state. This closes the remaining window.
   
   Tests: new `ConcurrentRequestsThrottlerCleanTest`. It runs the scheduled 
clean at an exact point instead of waiting 10 s:
   - `testCleanDoesNotRemoveStateInUse`
   - `testCleanAfterExchangeLookedUpState`: the race window.
   - `testCleanRemovesUnusedState`: idle states are still removed.
   
   Without the fix, 2 fail (`Expected CamelExecutionException to be thrown, but 
nothing was thrown.`). With only the idle check in `clean()`, 
`testCleanAfterExchangeLookedUpState` still fails, so both parts are needed. 
With the full fix, 3/3 pass. `*Throttl*`: 55 tests (camel-core) and 12 tests 
(camel-management), 0 failures.
   
   Note: the public methods of the protected inner class 
`ThrottlingState.tryAcquire/acquire` now declare `throws Exception`, because 
re-evaluating the max requests expression can throw.
   
   # 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]

Reply via email to