wolfSSL / wolfMQTT

wolfMQTT is a small, fast, portable MQTT client implementation, including support for TLS 1.3.
https://www.wolfssl.com
GNU General Public License v2.0
518 stars 156 forks source link

Reconnect problem: MqttSocket_Connect relies on incorrect client->flags status value #313

Open gojimmypi opened 1 year ago

gojimmypi commented 1 year ago

When MqttSocket_Connect is called but the client object loses a previously successful connection to the remote host, the connection logic skips the call to actually reconnect to the host:

rc = client->net->connect(client->net->context, host, port, timeout_ms);

This behavior was observed in an embedded environment (ESP32) connected to a WiFi router. The LinkSys WiFi router itself was connected to another router which during testing which had the WAN/Internet cable removed. See blog. The ETH0 cable was disconnected from Edgerouter to observe the device still "connected" to the local network, but not actually connected to the internet:

image

This problem is likely with the client object not properly setting flag when the device is disconnected from the internet and not just the local network. Specifically, this was observed to return 1 when the WAN network cable was disconnected (but the device itself was still connected to local subnet):

(client->flags & MQTT_CLIENT_FLAG_IS_CONNECTED)

The client->flags could probably be set manually in an end-user callback function, but this library should do that automatically.

This issue is similar to the Automatic connect function #41 feature request.

Further details in progress.