mqtt_connect(&client) does not return any value during operation, and the program is stuck in mqtt_connect(&client) and does not come out

When I connected mqtt on nRF9160, I found a strange problem, which caused the device to freeze and become bricked. The location cause was found to appear in err = mqtt_connect(&client), mqtt_connect(&client) does not return any value when running, and the program is stuck mqtt_connect(&client) does not come out. What is going on? It is easy to reproduce after a period of normal operation. The device is running on ncs1.5.1, modem V1.2.3.

Below is my mqtt file:

Parents Reply
  • Hi,

     

    george.zhou said:
    I did not close the socket

    You should close the socket, via the mqtt_disconnect() or mqtt_abort(). If not, you risk leaving the old socket still open after the mqtt_connect() call.

    george.zhou said:
    After a day of testing, the problem still reappeared, but it did not solve the problem. Encountered a new bug, please take a look at what is going on, thank you!

    Which new bug did you observe?

     

    Kind regards,

    Håkon

Children
  • Tested according to the method you said, and did not solve the problem, indicating that the problem I encountered is different from the problem you mentioned, and it should be a new problem.

    First of all, the connection to mqtt is blocked, and I did not reconnect to mqtt because the program is stuck in the mqtt connection and does not return, but once the mqtt connection is successful, I will use mqtt_disconnect() to close the socket after sending the data.I can make sure that the socket is closed every time before connecting mqtt

  • Hi,

     

    Could you try setting these configurations to see if the scenario improves?

    CONFIG_NRF_MODEM_LIB_SENDMSG_BUF_SIZE=2048
    CONFIG_NRF_MODEM_LIB_HEAP_SIZE=2048

     

    Kind regards,

    Håkon

  • Hi,

    I added the two macros you mentioned and tested them for a day on ncs1.6.0 and mfw_nrf9160_1.2.7, and found that the problem was improved. Some get stuck for 3 and a half minutes and return an error code, and sometimes get stuck for more than ten minutes and return an error code. The error returned is EINVAL. I will test for a few more days to see if the problem is completely solved. If it does solve the problem, I will test again on ncs1.5.1 and mfw_nrf9160_1.2.3 to see if this problem can also be solved. I will reply to the results after the test to you, thank you so much!

  • Hi,

    I tested one more day, unfortunately, the problem reappeared, stuck in mqtt connection with no return value all the time.

  • Hi,

     

    george.zhou said:
    I added the two macros you mentioned and tested them for a day on ncs1.6.0 and mfw_nrf9160_1.2.7, and found that the problem was improved. Some get stuck for 3 and a half minutes and return an error code, and sometimes get stuck for more than ten minutes and return an error code. The error returned is EINVAL.

    This is expected behavior if the nRF is unable to connect, due to network connectivity problems.

    george.zhou said:
    I tested one more day, unfortunately, the problem reappeared, stuck in mqtt connection with no return value all the time.

    And this was with which SDK and modem fw?

    The connect() call never returned?

     

    Kind regards,

    Håkon

Related