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

   # Description
   
   [CAMEL-27171](https://issues.apache.org/jira/browse/CAMEL-27171)
   
   `QuartzScheduledPollConsumerScheduler` (a polling consumer with 
`scheduler=quartz`) with a `scheduler.triggerId` looks up its trigger when it 
starts. When the trigger is already in the Quartz scheduler and the cron did 
not change, `startScheduler` still calls `scheduleJob(job, trigger)`, which 
throws `ObjectAlreadyExistsException`. The exception is ignored only with a 
clustered job store, so the route does not start:
   
   - a route stopped and started with `scheduler.deleteJob=false` (the trigger 
is kept on stop);
   - a persistent (JDBC) job store that is not clustered, after the application 
did not stop gracefully: the application does not start until the trigger is 
deleted from the database.
   
   The code means to reuse the trigger (it logs "Trigger with key ... is 
already present in scheduler. Only updating it.", and calls `rescheduleJob` 
when the cron changed); only the same-cron case falls through to `scheduleJob`.
   
   Also, `checkTriggerIsNonConflicting` reads the route id from the job data 
map of the trigger, but `doStart` stores it on the job, so the check never 
finds it. On main two routes with the same trigger id and group are caught only 
by the `ObjectAlreadyExistsException` above (and, with a clustered store, the 
second route starts and never polls, as the job runs the first route).
   
   Fix:
   - When the trigger is already in the scheduler with the same cron, 
`startScheduler` uses the stored trigger instead of scheduling it again (it 
schedules it if it was removed meanwhile).
   - `checkTriggerIsNonConflicting` reads the route id from the job of the 
trigger. With the first change this check is what keeps a second route from 
silently sharing the trigger of another route, so the two go together.
   - A start that fails on this check (dead code on main) now reports it. 
`FileConsumer.doStart` calls `startScheduler` in a `finally`, also when the 
start failed, so the failure was hidden: by a `NullPointerException` (no 
trigger yet), or by `Trigger does not reference given job!` when an earlier 
start of the same consumer had left its trigger. `startScheduler` now does 
nothing without a trigger, `unscheduleTask` no longer fails without one, and 
`doStart` clears the trigger of an earlier start, so the stop after a failed 
start does not unschedule the trigger with that key either, which is now the 
other route's (with `deleteJob=true`).
   - Upgrade guide (4.24): the start no longer fails, and a trigger key used by 
another route fails the start with an `IllegalArgumentException` naming that 
route, also with a clustered store.
   
   The job data map that `doStart` updates for an existing trigger (cron, 
CamelContext name) is still not stored, as on main (the changed-cron and 
clustered paths do not store it either). The stored job keeps the route id and 
the CamelContext (management) name of the run that created it, and the job 
finds the route by both; so with a persistent job store, a CamelContext whose 
management name changed between two runs starts but does not poll with the old 
trigger, as on main with a clustered store. Storing the updated job is a 
follow-up (it must not replace the trigger of another node in a clustered 
store).
   
   Also not changed (follow-up): `FileConsumer.doStart` (camel-file) starts the 
scheduler in a `finally` also when its start failed; this PR only makes the 
Quartz poll scheduler safe against it.
   
   Model: `QuartzPollTrigger.tla` (store with or without the trigger, two 
routes with the same key, start / stop with and without deleteJob / application 
kill): on main "a route of the trigger's own job can always start" is violated 
(3 states: the trigger is in the store, the route starts and fails); with the 
fix it holds, and so does "a started route polls" (48 distinct states).
   
   Tests: `FileConsumerQuartzSchedulerExistingTriggerTest`: restart with 
`deleteJob=false`; start with the trigger and job already in the scheduler (as 
left by an earlier run); a second route (`deleteJob=true`) that used the 
trigger key before fails to start with the route named, and the trigger of the 
first route is still in the scheduler afterwards. On main all three fail 
(`ObjectAlreadyExistsException` for the first two, and for the second route 
instead of the `IllegalArgumentException`); without the trigger reset in 
`doStart` the third still fails (`Trigger does not reference given job!`); with 
the change all three pass. camel-quartz module tests: 134 run, 0 failures 
(camel-cron: 7 run, 0 failures). The new class 20 times in one JVM: 60 run, 0 
failures.
   
   # 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-27171](https://issues.apache.org/jira/browse/CAMEL-27171).
   
   # 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 touched modules with the formatter and import-sort plugins; 
no option or generated file changes, only the hand-written upgrade guide entry. 
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