shashank created CAMEL-27043:
--------------------------------
Summary: camel-paho-mqtt5 - a reconnect while the Paho callback
thread is still in messageArrived may hang the client (needs reproduction,
maybe a Paho issue)
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
Found by the Paho MQTT 5 DST world of CAMEL-26958 (PR #30138): with
{{-Ddst.paho.strictCallbackThread=true}} about 8 to 9 % of the seeds fail
"every message is routed once the faults cleared" (100 of the first 1157
seeds). The default set of the world leaves this case out until it is
reproduced. *Needs reproduction*: so far this is read from the byte code of
Paho 1.2.5 ({{org.eclipse.paho.mqttv5.client}}) and modelled in the fake, not
seen against a broker. If it reproduces, it may be a Paho issue rather than a
Camel one.
h3. What the world shows
A connect that comes while the callback thread of the client is still in
{{messageArrived}} after the connection closed never completes. In the world
that happens when the connection is lost while a message is in the route, and
then either the consumer reconnects after a failed message (CAMEL-25793) or the
automatic reconnect of Paho runs, while that message is still in the route. The
client then stays connecting, the consumer delivers nothing more, and the route
stop cannot close the client ({{close()}} throws 32110, a connect in progress).
h3. Why (as read in Paho 1.2.5)
{{ClientComms.ConnectBG}} calls {{CommsCallback.start}} before it sends
CONNECT. {{start()}} only starts the thread again when its state is STOPPED,
and then waits until it is RUNNING. A disconnect or a lost connection asks the
thread to stop, but a thread that is still in {{messageArrived}} has not
reached STOPPED yet, so {{start()}} sets nothing and its wait does not end.
The fake leaves out the quiesce of a disconnect (Paho waits up to 30 seconds
for the callback queues to empty), so the window in the real client may be
smaller, or closed in some paths. The numbers above are of the fake only.
h3. Next steps
* Reproduce with a plain test against a broker (Mosquitto from test-infra): a
route that blocks in the first message, then the broker drops the connection,
and the consumer or the automatic reconnect connects while the route still
holds the message; check whether the connect completes once the route returns.
* If it hangs, check whether Paho 1.2.5 (and the latest Paho) is at fault and
report it upstream; the Camel side may then only need a guard (for example not
connecting from the callback thread while an exchange is in progress).
* Once settled, the world can check this case by default (drop
{{dst.paho.strictCallbackThread}}).
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)