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

   # Description
   
   [CAMEL-27083](https://issues.apache.org/jira/browse/CAMEL-27083)
   
   The consumers of a `scheduler:name` endpoint share a thread pool that 
`SchedulerComponent` keeps per name with a reference count. 
`SchedulerEndpoint.onConsumerStart` took a reference only when the consumer had 
no scheduler and no thread pool yet, and `onConsumerStop` released one on every 
stop.
   
   What went wrong:
   - A consumer that is stopped and started again in place (JMX 
`ManagedConsumer` stop/start, or a route policy that calls 
`stopConsumer`/`startConsumer`, such as the leader election policies of 
camel-zookeeper-master and camel-hazelcast, the usual way to run a scheduled 
route on the leader only) still had the pool and the scheduler of its first 
start. Its stop released the last reference, so the component shut the pool 
down. The second start took no reference and scheduled the poll on that pool: 
with the default thread pool profile the CallerRuns policy drops the task 
without an error. The route is Started and never polls again.
   - With two routes on the same scheduler name, a stop and start of route a 
and then a second stop released a reference that route a did not hold, and the 
pool was shut down under route b, which stopped polling too.
   - A consumer with its own `scheduledExecutorService` (or its own scheduler) 
never takes a reference, but its stop released one, with the same effect on the 
other routes of that name.
   
   A route stop and start through the route controller creates a new consumer, 
so it was not affected.
   
   Fix, in camel-scheduler only: the consumer records that it took a reference 
to the component's pool. Only then its stop releases one, and its next start 
takes the pool again (a new one if the old one was shut down) and gives it to 
the `DefaultScheduledPollConsumerScheduler` it created at its first start. A 
consumer with its own scheduler or thread pool is left alone, as before.
   
   Tests: `SchedulerConsumerRestartTest` (camel-core, where the scheduler tests 
are):
   - a consumer stopped and started with `ServiceHelper` must not use a shut 
down pool, and must poll again;
   - routes a and b on `scheduler://foo`: after a stop, start and stop of route 
a, the pool of route b is not shut down and route b polls;
   - route d on `scheduler://bar` and route c on the same name with its own 
`scheduledExecutorService`: stopping route c leaves the pool of route d running.
   
   Without the change all three fail (the pool is shut down). With it the 
scheduler, timer, scheduled poll and scheduler health check tests of camel-core 
pass (69 run, 0 failures, 1 skipped), 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-27083](https://issues.apache.org/jira/browse/CAMEL-27083).
   
   # 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 camel-scheduler 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]

Reply via email to