qcom_mqtt_connect doesn't clean up old mqtt handle when failed.
Join Date: 12 Feb 17
Posts: 8
Posted: Sat, 2018-09-01 00:27
Hi,
I'm working with MQTT on qca4010.
My device intends to connect to the broker so that to connect to the broker I did below code
mqtt_err = qcom_mqtt_connect(&connectParams);
while (mqtt_err != 0)
{
printf("mqtt_connect res=%d\r\n", (int) mqtt_err);
mqtt_err = qcom_mqtt_connect(&connectParams);
tx_thread_sleep(500);
}
when the broker was on, the connect function worked well, but when the borker was not ready, I saw in the console log that each time calling qcom_mqtt_connect(), the system create a new handle and use that to open socket and connect to the broker. After 12 times connect failure, the system then couldn't create a new handle and didn't open socket to connect to broker any more as below log. So after 12 times trying to connect, the client can't connect to broker if it is available after that.
MQTT_connect start
SOCK_OPEN: index 11 handle 4351784
_tcp_sock_connect 1420
SOCK_CONNECT: index 11 handle 4351784 res -1
MQTT_connect mqtt_result = -3
Connect_Broker fail
MQTT disconnect: rc=-6
MQTT_connect start
MQTT_connect mqtt_result = -3
Connect_Broker fail
MQTT disconnect: rc=-6
MQTT_connect start
MQTT_connect mqtt_result = -3
Connect_Broker fail
MQTT disconnect: rc=-6
My question is that, is there anyway for the client to wait for the broker to be ready before connect since in my case some time client should need to wait for the broker to come up.
Hi ,
If broker is not ready , DUT will not Receive ACK and it will show message MQTT connect failed . Have you registered the disconnect handler ?
If connect failed , you can call qcom_mqtt_disconnect manully . It will close the socket and free all resource.
If everytime you will call qcom_mqtt_conect after connect failed and will not call qcom_mqtt_disconnect, it will create a new handle and once it will reach to the maximum number , it will fail to ctreate socket too.
You can use a timer to wait for the required time for clinet to connect to broker . Can you please let me know your use case?
Thanks