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

   # Description
   
   [CAMEL-26909](https://issues.apache.org/jira/browse/CAMEL-26909)
   
   Follow-up of #29525 (CAMEL-26741, an `Error` of a processor fails the 
exchange) and of CAMEL-24286 (a `BackgroundTask` whose supplier throws).
   
   `BackgroundTask` (camel-support) runs its supplier from a task scheduled 
with `scheduleWithFixedDelay`. Since CAMEL-24286 an exception of the supplier 
marks the task as failed, unregisters it and releases the caller of `run()` 
before it is thrown on (which ends the schedule). An `Error` that is not a 
`VirtualMachineError` (such as a `NoClassDefFoundError` of the client library a 
task connects with) was not caught there: it ended the schedule, and a `run()` 
with an unlimited duration waited forever (with a time budget, until the budget 
ran out), with the task left in the `TaskManagerRegistry` and its status 
`Active`. Tasks that a caller waits on with `run()` and an unlimited duration, 
with a supplier that catches only `Exception`, include the connect of 
camel-ftp/sftp (`SftpOperations` holds its lock while it waits), the reconnect 
of camel-kafka, camel-kafka-share, camel-pgevent and of the camel-smpp consumer 
and producer (which hold their reconnect lock while they wait), and the p
 olling of camel-mongodb-gridfs. A task started with `schedule()` (the start of 
the delegated consumer of camel-master, the connection recovery of camel-sjms) 
has no caller waiting: there the `Error` ended the schedule and left the task 
`Active` in the registry.
   
   Change: `runTaskWrapper` handles such an `Error` as an exception (the same 
catch): the task is `Failed` with it as its cause, `run()` returns false, and 
the task is unregistered; the `Error` is then thrown on, as the exception is, 
which ends the schedule. The `Error` is logged at WARN, as nothing else reads 
it (the `Future` it is thrown on to is cancelled by `run()`, or not read; the 
components log their own exceptions). A `VirtualMachineError` (such as an 
`OutOfMemoryError` or a `StackOverflowError`) is left as before: it is thrown 
on without releasing the caller, so a `run()` with an unlimited duration still 
waits for it, as for the rest of the CAMEL-26741 series, which does not handle 
a `VirtualMachineError`.
   
   Not changed: `ForegroundTask` runs the supplier on the caller's thread, so 
an `Error` reaches the caller. A task started with `schedule()` keeps 
`isRunning()` true after it failed, and camel-sjms decides on it whether to 
schedule a new connection recovery (follow-up JIRA, drafted).
   
   Tests, `BackgroundTaskRegistryTest`: the test of CAMEL-24286 (an 
unlimited-duration task whose supplier throws an `IllegalStateException`) now 
also runs with a `NoClassDefFoundError`, and both check the status `Failed` and 
the cause; a new test schedules (`schedule()`) a task whose supplier throws a 
`NoClassDefFoundError`: the task becomes `Failed` and leaves the registry. 
Without the change the two new tests fail on main (`run()` does not return 
within 10 seconds; the scheduled task stays `Active`); the exception case 
passes as before. With it the task tests of camel-core pass (37 run, 0 
failures), 20 runs of `BackgroundTaskRegistryTest` in one JVM pass (120/120), 
and the camel-core tests pass (9218 run, 0 failures; 11 errors, all 
`DumpModelAsYaml*`/`DumpModel*` tests that fail with `NoClassDefFoundError: 
OgnlExpression` from a stale camel-yaml-io jar in my local repository, 
unrelated).
   
   No documentation or upgrade guide change: nothing changes for an exception 
or a `VirtualMachineError`, and for another `Error` the only difference is that 
`run()` returns (and the `Error` is logged), where before it could wait forever.
   
   # 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-26909](https://issues.apache.org/jira/browse/CAMEL-26909).
   
   # 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 with the formatter and import-sort plugins and 
ran the camel-core tests. 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