[
https://issues.apache.org/jira/browse/CAMEL-25024?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18119983#comment-18119983
]
Andrea Cosentino commented on CAMEL-25024:
------------------------------------------
Note on the scope of the fix, since the description left it open: the change
streams consumer still advances its resume token past a failed event, and that
cannot be addressed in the catch block. The failed event's token is not
committed, but the next event that succeeds commits its own, so the position
moves regardless. Preventing it means the consumer has to stop committing or
reprocess, which is a redesign rather than a bug fix, so it is out of scope
here and worth a separate issue if the behaviour is wanted.
What the PR does fix is the silence - both consumers now report the failure
through the ExceptionHandler, so bridgeErrorHandler works - and the tailable
consumer no longer records a failed record as consumed.
----
_Claude Code on behalf of oscerd (Andrea Cosentino)._
> camel-mongodb - the consumers discard a failed exchange and advance past it
> ---------------------------------------------------------------------------
>
> Key: CAMEL-25024
> URL: https://issues.apache.org/jira/browse/CAMEL-25024
> Project: Camel
> Issue Type: Bug
> Components: camel-mongodb
> Reporter: Andrea Cosentino
> Assignee: Andrea Cosentino
> Priority: Major
>
> h3. Summary
> Both MongoDB consumers swallow a route failure without a trace and then move
> their position past the
> message that failed, so the exchange is lost and nothing records it.
> h3. Details
> {{MongoDbChangeStreamsThread.doRun()}}:
> {code:java}
> try {
> consumer.getProcessor().process(exchange);
> this.resumeToken = currentResumeToken;
> commitManager.recordResumeToken(currentResumeToken);
> commitManager.commit();
> } catch (Exception ignored) {
> }
> {code}
> {{MongoDbTailingThread.doRun()}}:
> {code:java}
> try {
> consumer.getProcessor().process(exchange);
> } catch (Exception e) {
> // do nothing
> }
> tailTracking.setLastVal(dbObj);
> {code}
> Neither calls {{getExceptionHandler()}}, so {{bridgeErrorHandler}} has no
> effect on these consumers and a
> route failure produces no log output whatsoever - the empty catch discards
> the exception entirely.
> The position advances regardless:
> * *Change streams*: the failed event's resume token is not committed, but the
> next event that succeeds
> commits its own, so the persisted position steps over the failure. The
> event is skipped permanently and
> silently.
> * *Tailable cursor*: {{tailTracking.setLastVal(dbObj)}} sits outside the try,
> so it runs even when
> processing threw. With {{persistentTailTracking=true}} the record is
> skipped across restarts too.
> h3. History
> The empty catch predates the visible git history: it is already present in
> the 2019-08-14 commit that
> renamed {{camel-mongodb3}} to {{camel-mongodb}}, and no issue has touched it
> since. It does not look like
> a considered decision, and nothing documents the at-most-once behaviour it
> produces.
> h3. Proposed fix
> Hand the failure to {{getExceptionHandler()}} in both consumers, as other
> Camel consumers do, so that it
> is logged and {{bridgeErrorHandler}} works. Move {{setLastVal}} inside the
> success path of the tailable
> consumer so a failed record is not marked as consumed. Whether a failure
> should also stop the position
> from advancing in the change-streams consumer is a behaviour change worth an
> upgrade-guide note.
> ----
> _Reported by Claude Code on behalf of oscerd (Andrea Cosentino)._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)