[bug #59313] Possible faulty behavoir in mqtt_close() function

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[bug #59313] Possible faulty behavoir in mqtt_close() function


                 Summary: Possible faulty behavoir in mqtt_close() function
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: ondrej_lufinka
            Submitted on: Wed 21 Oct 2020 10:52:37 AM UTC
                Category: Platform ports
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: git head




I use LwIP on STM32 MCU. I have a working combination of LwIP + MbedTLS +
MQTT. I found a possible faulty behavior in the function:

static void mqtt_close(mqtt_client_t *client, mqtt_connection_status_t

According to the MQTT standard, a client should send the DISCONNECT (ID = 14)
packet before closing the connection. This function terminates the connection
directly without sending this packet. In my case, I connect to the Amazon AWS
service, and this behavior led to this error:

1. I set Last Will Testament (LWT) before I call mqtt_connect()
2. I open the connection using mqtt_connect()
3. When the connection is lost (e.g. I unplug the ethernet cable from my
device) - LWT is correctly published to AWS
4. But when I close the connection from code (calling mqtt_disconnect(), LWT
should not be published
    - according to the MQTT specs
section 3.14.4
    - this is caused because of the missing DISCONNECT packet
5. When I added this code to the begging of the mqtt_close() function, it
works OK:

   /* If we have memory -> send disconnect packet */
   if (mqtt_output_check_space(&client->output, 0) != 0) {

     /* Append fixed header for disconnect packet */

     /* Send it */
     mqtt_output_send(&client->output, client->conn);

Can you please verify this behavior and possible solution?
Thank you very much.


Reply to this item at:


  Message sent via Savannah

lwip-devel mailing list
[hidden email]