Croway opened a new pull request, #30015: URL: https://github.com/apache/camel/pull/30015
# Description Backport of #27918 ([CAMEL-25679](https://issues.apache.org/jira/browse/CAMEL-25679)) to `camel-4.18.x`. The tailable (default `consumerType`) and change streams consumers of camel-mongodb read from a cursor on one thread. After a failed read the thread waits `cursorRegenerationDelay` and opens a new cursor, but on 4.18.x it does so outside the `try` of the loop in `MongoAbstractConsumerThread.run()`. While the server is still unreachable, opening the cursor fails after the driver's server selection timeout (30 s by default) with `MongoTimeoutException`, and the exception ends the thread. With default options, a MongoDB outage of about 30 to 60 seconds (restart, slow replica set failover, network outage, maintenance) is enough: the consumer stops reading for good while the route stays Started, and the only trace is the uncaught exception printed on stderr. Only a restart of the route brings it back. Every 4.18.x release has this. With the fix the new cursor is opened inside the `try`, so a failure is logged as a WARN ("Will try again on next poll") and retried after `cursorRegenerationDelay` until the server is back or the consumer is stopped. A cursor opened while the consumer is stopping is closed, the `cursor` field is volatile, and an interrupt ends the loop. Only the failure path changes; no option or default changes. ## Difference from a straight cherry-pick - Commit 1 is `git cherry-pick -x 3af2c90d63ad`, without conflicts. The production change (`MongoAbstractConsumerThread`, +18/-5) is identical to the one on `main`. - Commit 2 changes one line of the new test `MongoDbConsumerCursorRegenerationTest`. In the change streams test, the mock event's document key is now an `ObjectId` instead of an `Int32`. On 4.18.x, `MongoDbChangeStreamsThread` reads the key with `getObjectId("_id")`, because CAMEL-25025 (which accepts other key types) is not on this branch. With the `Int32` key from `main`, no exchange is created, and the test fails for that reason alone (`Expected: <1> but was: <0>`). Production code is unchanged. Because of this test change, this is not a straight cherry-pick. # Target - [x] I checked that the commit is targeting the correct branch (`camel-4.18.x`, LTS) # Tracking - [x] [CAMEL-25679](https://issues.apache.org/jira/browse/CAMEL-25679), original PR #27918 # Tests Run on this branch (4.18.6-SNAPSHOT) with `./mvnw -pl components/camel-mongodb install`: - `MongoDbConsumerCursorRegenerationTest`: 4/4 pass. With only commit 1, 3/4 pass; the change streams case fails as described above. - camel-mongodb unit tests: 8 run, 0 failures. - camel-mongodb integration tests, run locally against a MongoDB container by the same `install`: 150 run, 0 failures, 1 skipped (a `@Disabled` test in `MongoDbIndexIT`). This includes `MongoDbTailableCursorConsumerIT` (8) and `MongoDbChangeStreamsConsumerIT` (4). - `mvn formatter:format impsort:sort` on the module: no changes. Not run: a real MongoDB outage against the backport. _Claude Code on behalf of Croway_ -- 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]
