Forums - qcom_mqtt_connect doesn't clean up old mqtt handle when failed.

2 posts / 0 new
Last post
qcom_mqtt_connect doesn't clean up old mqtt handle when failed.
chau-nm
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.
  • Up0
  • Down0
jbhanu Moderator
Join Date: 6 Feb 17
Posts: 80
Posted: Mon, 2018-09-03 09:43

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 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.