[
https://issues.apache.org/jira/browse/CAMEL-27043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150444#comment-18150444
]
Claus Ibsen commented on CAMEL-27043:
-------------------------------------
A friendly reminder: fixing bugs is a priority, and the Camel 4.24.0 release is
coming up. If you cannot work on this ticket before then, please unassign it so
someone else can pick it up.
_Claude Code on behalf of Claus Ibsen (davsclaus)_
> camel-paho-mqtt5 - manualAcksEnabled: the reconnect after a failed message
> hangs while another message is still in a synchronous route, and on Artemis
> the consumer ends up connected but idle, with messages lost
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27043
> URL: https://issues.apache.org/jira/browse/CAMEL-27043
> Project: Camel
> Issue Type: Bug
> Components: camel-paho-mqtt5
> Reporter: shashank
> Assignee: shashank
> Priority: Major
>
> h3. What happens
> With {{manualAcksEnabled=true}}, QoS 1, {{cleanStart=false}} and
> {{sessionExpiryInterval}} greater than 0, a failed exchange makes the
> consumer disconnect and connect its own client again after the backoff delay
> (CAMEL-25793), so that the broker sends the message again. The route is
> synchronous by default, so the exchange runs on the callback thread of Paho.
> When another message is still in the route at that moment (a route step
> slower than the reconnect delay, 1 second for the first failure), the connect
> never completes.
> The defect is in the lifecycle of the client threads in Paho 1.2.5, read in
> its sources. {{MqttClient.disconnect}} quiesces only the message queue, which
> is already empty (the callback thread took the message off the queue before
> handling it). {{CommsCallback.stop()}} then sets its target state to STOPPED
> and returns at once, without waiting for the thread that is still in
> {{messageArrived}}. The next connect of the same client
> ({{ClientComms.ConnectBG}}) calls {{CommsCallback.start()}} before it sends
> the CONNECT. {{start()}} starts a thread only when the current state is
> STOPPED, which it is not while the old thread is still in the route, and then
> sleeps in {{while (!isRunning())}} forever, as nothing sets the target state
> back to RUNNING. {{CommsSender}} has the same start/stop pattern, and an
> earlier reproduction hung there. The reconnect thread of the consumer waits
> on the connect token without a time limit.
> Against Artemis 2.57 (embedded, MQTT 5) it gets worse: the broker closes a
> socket that sends no CONNECT within 10 seconds, the consumer's catch
> schedules another reconnect, that one connects, and the stuck connect then
> sends its stale CONNECT on the new connection, so the broker disconnects the
> client with Session taken over (0x8E). Each time, the message still in the
> route loses its PUBACK, is sent again, is in the route at the next reconnect,
> and the next connect hangs again, also after the failed message itself was
> acknowledged. After about 45 seconds Artemis deleted the pending messages of
> the subscription queue and the consumer stayed connected with no deliveries:
> the route is Started, {{isConnected()}} is true, and the messages are lost.
> h3. How to reproduce
> A route
> {{from("paho-mqtt5:topic?qos=1&manualAcksEnabled=true&cleanStart=false&sessionExpiryInterval=60&clientId=c")}}
> whose processor throws for the first delivery of {{fail-1}} and waits 3
> seconds (any time longer than the reconnect delay) for the first delivery of
> {{slow-2}}. Publish {{fail-1}} and {{slow-2}}, then {{after-3}}. The consumer
> never routes {{fail-1}} again nor {{after-3}}; a thread dump shows {{MQTT
> Con}} in {{CommsCallback.start}} called from {{ClientComms$ConnectBG.run}},
> and {{PahoMqtt5-Reconnect}} in {{MqttClient.connectWithResult}} called from
> {{PahoMqtt5Consumer.reconnect}}. Reproduced with the real Paho 1.2.5 client
> against the embedded Artemis MQTT broker of the module's tests (new
> {{PahoMqtt5ConsumerReconnectWhileRoutingTest}}), and with a TLA+ model of the
> consumer and the Paho callback lifecycle.
> h3. Fix
> The root defect is in Paho 1.2.5; Camel now avoids triggering it. The
> reconnect after a failed exchange no longer connects the same {{MqttClient}}
> again: it disconnects and closes it, and connects a new client with the same
> client id, which resumes the session the broker kept. A new client has its
> own callback and sender threads, so its connect does not wait for the threads
> of the old connection. The callback is set on the new client before its
> connect, as at start.
> Exchanges still in the route on the closed client are not acknowledged (the
> broker sends their messages again to the new client, so they are routed
> twice, at-least-once as for QoS 1 in general) and do not reset the backoff,
> as for an exchange that completes after a stop (CAMEL-27040). A lock orders
> the replacement against the stop (the stop either closes the new client or
> the new client is never used, so no left-over client takes the session, see
> CAMEL-27041) and against the acknowledgement of an exchange (never on a
> closed client). A failed connect or a failed creation of the new client is
> retried with the backoff. {{getClient()}} of the consumer returns the new
> instance afterwards; the component page and the 4.24 upgrade guide say so.
> Not changed: Paho's own automatic reconnect after a lost connection
> reconnects the same client and can still hang the same way while a message is
> in the route; that is up to Paho.
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)