[
https://issues.apache.org/jira/browse/CAMEL-27385?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-27385 started by shashank.
----------------------------------------
> camel-core - Scheduled poll consumer: a poll that runs over a stop and start
> can mark the restarted consumer ready or cancel its schedule
> -----------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27385
> URL: https://issues.apache.org/jira/browse/CAMEL-27385
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Reporter: shashank
> Assignee: shashank
> Priority: Major
>
> h3. What happens
> {{ScheduledPollConsumer.doStop}} does not wait for a poll that is running (it
> cancels the futures and shuts the executor down). CAMEL-25109 added the
> {{generation}} counter so such a poll does not write the state of the
> consumer after the stop. The guard is check-then-act without a lock, and some
> writes have no guard:
> * {{forceConsumerAsReady()}} has no generation check. Many components call it
> inside {{poll()}} once their remote call returns (aws2-sqs, aws2-s3,
> aws2-kinesis, minio, couchbase, ftp, ...). When the route is stopped and
> started during such a call (an SQS long poll can take 20 s), the old poll
> marks the restarted consumer ready before it has polled: the readiness check
> reports UP, and stays UP while the first poll of the restarted consumer hangs
> (unless {{healthCheckMaxPollDuration}} is set); only a failed poll turns it
> DOWN.
> * With {{repeatCount}}, a run from before the stop that decided to stop
> firing calls {{scheduler.unscheduleTask()}} after the restart. The scheduler
> is reused, so this cancels the tasks of the restarted consumer: the consumer
> is Started but never polls again, and nothing reports it. Its
> {{counter.incrementAndGet()}} can also use up the repeat count of the
> restarted consumer.
> * A stop and start between the generation check and the writes of a poll
> (also in the greedy branch and in {{onPolled}}) leaves {{firstPollDone}}, the
> error counter and {{lastErrorDetails}} of the old poll in the restarted
> consumer.
> * The backoff block writes {{backoffErrorBase}} and {{backoffCounter}}
> without a generation check, so after a restart the error backoff of the new
> consumer can start later than configured.
> h3. How to reproduce
> A consumer whose {{poll()}} calls {{forceConsumerAsReady()}} after a blocking
> call: hold the call, stop and start the consumer, release the call.
> {{isConsumerReady()}} is true although the restarted consumer has not polled.
> A consumer with {{repeatCount=1}}: hold the second run just before it calls
> {{unscheduleTask()}}, stop and start the consumer, release the run. The
> restarted consumer is Started, but {{isSchedulerStarted()}} is false.
> Found with a TLA+ model.
> h3. Fix
> One lock in the consumer: {{doStop}} increments the generation and clears the
> state under it, and a poll checks that the generation is still its own and
> writes the state under it (the backoff block, the repeat count and
> {{unscheduleTask()}}, the greedy writes, {{onPolled}} and the final writes).
> A run that sees the consumer was stopped since it started does not go on.
> {{forceConsumerAsReady()}} called from a poll checks the generation of that
> poll under the lock; a call from another thread works as before. The lock is
> never held while polling, while the poll strategy runs, or while the
> exception handler runs.
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)