shashank created CAMEL-26915:
--------------------------------

             Summary: camel-nats - a quick stop and start of a consumer: the 
task of the stopped run can subscribe and take over the fields of the new run
                 Key: CAMEL-26915
                 URL: https://issues.apache.org/jira/browse/CAMEL-26915
             Project: Camel
          Issue Type: Bug
          Components: camel-nats
            Reporter: shashank
            Assignee: shashank


Follow-up of CAMEL-26462 and CAMEL-26884, the gap left open by both (listed in 
their PRs, #29042 and #29788).

{{NatsConsumer}} subscribes on a task of its executor, and the task checks 
{{isRunAllowed()}} to see whether the consumer stopped meanwhile. That is the 
state of the consumer, not of a run. On a quick stop and start (for example a 
route restart) while the task of the first run is still in its subscribe:
* the stop of the first run does not see the dispatcher or the subscription the 
task is about to set, and the interrupt of {{shutdownNow}} does not always end 
the subscribe;
* when the subscribe returns, the consumer runs again, so the task of the old 
run sees {{isRunAllowed()}} true, keeps its subscription and writes 
{{dispatcher}}, {{dispatcherHandler}} and {{jetStreamSubscription}}, which may 
overwrite those of the new run;
* the next stop then ends only what the fields point at: the dispatcher or 
subscription of the other run is never closed, and the route can receive each 
message twice (a standard or push subscription of each run, or two pull fetch 
loops).

Also, after the task of a run gave up (its subscribe failed), the fields still 
point at the closed dispatcher of that run until the next run sets them.

Expected: each start of the consumer gets a run token (a counter or an object), 
the task works on the token of its run, it sets the fields only while its run 
is the current one, and it ends what it made itself when its run is no longer 
current (with the interrupt cleared for the unsubscribe, as in CAMEL-26884). A 
stop clears the fields of its own run.

Not seen in production; found while reviewing the stop path for CAMEL-26462 and 
CAMEL-26884. The window is a subscribe in flight across a stop and a start.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to