[
https://issues.apache.org/jira/browse/CAMEL-27040?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-27040:
--------------------------------
Fix Version/s: 4.24.0
> camel-paho-mqtt5 - manualAcksEnabled: an exchange that completes after the
> consumer stopped fails with a NullPointerException, or acknowledges a packet
> id on the client of the next start
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27040
> URL: https://issues.apache.org/jira/browse/CAMEL-27040
> Project: Camel
> Issue Type: Bug
> Components: camel-paho-mqtt5
> Reporter: shashank
> Assignee: shashank
> Priority: Minor
> Fix For: 4.24.0
>
>
> Noticed while reading the consumer (and listed for the Paho DST world of
> CAMEL-26958, PR #30138, which does not drive it: its operator stops the route
> only while no message is in the route). Reproduced with a plain unit test
> (below).
> h3. What happens
> With {{manualAcksEnabled=true}} each exchange gets an on-completion that
> acknowledges the message: {{onComplete}} calls
> {{PahoMqtt5Consumer.this.client.messageArrivedComplete(id, qos)}},
> {{onFailure}} calls {{rollback}}, which acknowledges a message the broker
> does not send again or reconnects for one it does.
> A route stop does not wait for the exchanges in flight before it stops the
> consumer ({{DefaultConsumer}} is not {{Suspendable}}, so the shutdown
> strategy stops it first and then waits for the in-flight exchanges).
> {{doStop}} closes the own client of the consumer and sets {{client}} to null.
> An exchange that completes after that:
> * {{onComplete}} throws a {{NullPointerException}} (only {{MqttException}} is
> caught), which the unit of work logs as a WARN with the stack trace;
> * after the consumer started again (route restart, supervising controller),
> {{client}} is the new client: {{onComplete}} acknowledges the packet id of
> the old connection on the new client, and {{onFailure}} acknowledges it
> there, or makes the new client reconnect. A packet id names a message of one
> session only (MQTT 5, 2.2.1), so this can acknowledge another message the new
> client has in flight.
> h3. Expected
> A message is acknowledged on the client it arrived on. Once that client is
> closed nothing can be acknowledged: on a session the broker keeps
> (cleanStart=false, sessionExpiryInterval > 0) the broker sends the
> unacknowledged QoS 1 message again when a client with the same client id
> connects (MQTT 5, 4.4), so with a fixed {{clientId}} the next start gets it
> again (a generated client id is new on each start, and the old session
> expires); otherwise the session ended with the connection. In both cases the
> completion has nothing to do.
> h3. Reproduction
> New {{PahoMqtt5ConsumerAckAfterStopTest}} (a mocked {{MqttClient}}, the real
> consumer and a {{DefaultCamelContext}}): an exchange created by the consumer
> completes after {{stop()}}: NPE in {{onComplete}} on main; after {{stop()}}
> and {{start()}} with a new client, {{onComplete}} and {{onFailure}}
> acknowledge packet id 7 on the new client on main. Controls: an exchange that
> completes while the consumer runs is acknowledged, and so is one of a client
> given with the {{client}} option after a restart.
> Not changed: after an automatic reconnect of Paho on the same client, an
> exchange of the old connection still acknowledges its packet id on the new
> one (follow-up).
> h3. Fix
> The on-completion keeps the client the message arrived on; {{onComplete}} and
> {{rollback}} do nothing (DEBUG log) when the current client is null or
> another client. A client given with the {{client}} option is the same object
> before and after a restart, so its messages are acknowledged as before.
> Branch {{camel-paho-mqtt5-ack-after-stop}}.
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)