Croway opened a new pull request, #30161: URL: https://github.com/apache/camel/pull/30161
JIRA: [CAMEL-27008](https://issues.apache.org/jira/browse/CAMEL-27008) Follow-up of CAMEL-26995 (#30072), which left this path out ("Not changed" in its description). ### What was wrong With a `RecoverableAggregationRepository` that has a `deadLetterUri` and `maximumRedeliveries`, `RecoverTask.run` (`AggregateProcessor`) moves an exhausted recovered exchange to the dead letter channel and then calls `recoverable.confirm(camelContext, exchangeId)`, unguarded: - When that confirm throws (for example `JdbcAggregationRepository` while the database is not available), the exception leaves the scan loop and is logged by the outer catch (`Error during recover task. This exception is ignored.`). The id is not kept as unconfirmed and its redelivery state still says it is exhausted, so on the next pass it is recovered and moved to the dead letter channel **again**, at every pass while the confirm fails. - The ids after it in the scan are skipped in that pass, and never handled while that confirm keeps failing and comes first in the scan. - The path calls `confirm`, not `confirmWithResult` as the javadoc of `AggregationRepository.confirm` says for a recoverable repository, so a `false` result is ignored: the exchange is moved again if the repository still returns it. ### The fix - After the exchange was moved to the dead letter channel, the recover task calls `confirmWithResult`. When it throws or returns `false`, the id goes to `unconfirmedCompleteExchanges`, as in `AggregateOnCompletion.onComplete` since CAMEL-26995: the next passes retry the confirm (`retryConfirm`) and do not move the exchange again, and the current pass goes on with the other ids. A throw is logged at WARN with the exchange id and the stack trace. A `VirtualMachineError` is rethrown, as elsewhere in the class (CAMEL-26881). - The redelivery state of the exchange is removed once it was moved, as `onComplete` and `discard` do. It was kept for good before (until the route stopped), although it is not read again. - The javadoc of `RecoverableAggregationRepository.confirmWithResult` says it is also invoked after a move to the dead letter channel. A failed send to the dead letter channel is not changed: the exchange is not confirmed and is moved again on the next pass, as before. ### Tests `AggregateRecoverableConfirmFailureTest` (camel-core): the in-memory repository now has `deadLetterUri=mock:dead` and `maximumRedeliveries=2`, and the route fails the groups listed by a test. Three new tests; each fails without the fix: - `testDeadLetterConfirmThrows`: the confirm after the move throws once. Before: `expected: <[A+B]> but was: <[A+B, A+B]>`. - `testDeadLetterConfirmReturnsFalse`: the confirm returns `false` once (the repository keeps the exchange). Before: `expected: <[A+B]> but was: <[A+B, A+B]>`. - `testDeadLetterConfirmKeepsThrowing`: the confirm of `A+B` always throws, and `A+B` comes first in the scan. Before: `C+D` is never moved nor confirmed (await timeout), and `A+B` was moved to `mock:dead` about 100 times in 10 seconds. The three tests of CAMEL-26995 in the same class pass before and after. With the fix, `mvnd test -pl core/camel-core -am -Dtest='*Aggregat*' -Dsurefire.failIfNoSpecifiedTests=false` passes (308 tests, 5 skipped), and so do the camel-sql `*Jdbc*Aggregat*Test` tests, which use the real `JdbcAggregationRepository`, including `JdbcAggregateRecoverDeadLetterChannelTest` and `JdbcAggregateRecoverDeadLetterChannelFailedTest` (63 tests). No upgrade-guide entry: an exchange is no longer moved to the dead letter channel more than once, which is what the confirm after the move is for ("so we wont recover it again"). The repositories in Camel other than `JdbcAggregationRepository` use the default `confirmWithResult`, which calls `confirm` and returns `true`, so for them only the handling of an exception changes. ### For reviewers - As for CAMEL-26995: when a confirm throws *after* the row was deleted, or returns `false` because the row is gone, the scan no longer returns the id, so it stays in `unconfirmedCompleteExchanges` (one id per such failure). Pruning that set against the scan would bring back a duplicate for repositories whose scan can miss an entry for a while, so I left it as it is. - On 4.18.x, `RecoverTask.run` has no catch (CAMEL-24141 is not there), so a throwing confirm after the move ends the scheduled recover task instead. A backport would need to account for that. _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]
