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

   # Description
   
   [CAMEL-25711](https://issues.apache.org/jira/browse/CAMEL-25711)
   
   `GridFsConsumer` polls with a `BackgroundTask` that has no duration limit. 
In `processCollection` only `getProcessor().process(exchange)` was inside a 
`try`. The query of the bucket, the cursor, the `findOneAndUpdate` that marks a 
file `processing` (file attribute strategies), `openDownloadStream` and the 
update of the persistent timestamp were not. When one of them threw, for 
example a `MongoTimeoutException` because MongoDB could not be reached for 
longer than the server selection timeout, the exception left the task. 
`BackgroundTask` then marks the task failed and rethrows on the scheduler 
thread, so the poll was never scheduled again. The consumer stayed started, 
routed nothing until the route was restarted, and nothing was logged. 
CAMEL-24286 names this path, but its fix changed only `BackgroundTask` (`run()` 
returns now). The poller still ended.
   
   With `PersistentTimestamp` / `PersistentTimestampAndFileAttribute`, `run()` 
also read the timestamp collection before scheduling the polls. If MongoDB was 
not reachable when the route started, no poll was ever scheduled.
   
   Changes (`GridFsConsumer` only):
   - The task calls a new `poll` method. It catches an exception of the poll, 
reports it through the consumer's `ExceptionHandler` and returns `false`, so 
the next poll tries again after `delay`. Only the first failure of a run of 
failures goes to the handler (WARN with the stack trace by default). The 
following ones are logged at DEBUG, as the polls run every `delay` (500 ms by 
default), and one INFO line says when a poll works again. With 
`bridgeErrorHandler=true` it is therefore also only the first failure that is 
routed to the error handler of the route. The camel-mongodb consumer thread 
also catches the exception of a poll and goes on 
(`MongoAbstractConsumerThread`, CAMEL-16025), but logs every failure at WARN 
with the stack trace.
   - The persistent timestamp is now read by the first poll that reaches 
MongoDB, not by `run()`, so a failure there is retried in the same way. Its 
value and the stored document are unchanged.
   
   Tests:
   - Two new tests in `GridFsConsumerTimestampTest` use the fake bucket already 
in that class (Mockito, no MongoDB):
     - `consumerKeepsPollingAfterAFailedPoll` runs for each of the 5 query 
strategies. The first 2 queries of the bucket throw `MongoTimeoutException`, 
then a file is stored, and the file must be routed once.
     - 
`persistentTimestampStrategyKeepsPollingWhenTheTimestampCannotBeReadAtStart`: 
the first read of the timestamp collection throws, and a stored file must still 
be routed.
     - Bounded waits only, no sleeps.
   - Without the change all 6 cases fail with `the consumer did not poll 3 
times`.
   - With the change the camel-mongodb-gridfs unit tests pass: 18 run, 0 
failures, 0 errors, 6 skipped (the 6 skipped are the container integration 
tests).
   
   What is not changed:
   - A file that a file attribute strategy marked `processing` before the poll 
failed keeps that attribute, as before.
   - A failed exchange is still marked `done` (unchanged).
   - No option or default changes.
   
   What was not run: the container integration tests (`GridFsConsumerIT`) and a 
real MongoDB outage.
   
   # 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-25711](https://issues.apache.org/jira/browse/CAMEL-25711).
   
   # 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 camel-mongodb-gridfs and the modules it depends on, including the 
formatter and import-sort plugins, and ran the camel-mongodb-gridfs unit 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