Commit 95f5191c authored by Datong Sun's avatar Datong Sun Committed by Nathaniel Wesley Filardo
Browse files

Fixed an regression that MQTT client timer is disarmed prematurely when

connecting to server.

Inside af426d03, the `mqtt_socket_timer`
function was modified so that instead of checking the presense of
allocated `mud->pesp_conn` structure, `mud->connected` field was used
on determining if the timer need to be disarmed.

However, this is not entirely correct. If the TCP socket is actively
connecting and haven't timed out yet, then `mud->connected` is also
`false` and the timer will think the connection is broken and
disarms itself. This has two consequences:

* The connection timeout counter is no longer decremented and checked
* After connection succeeds, keepalive heartbeat is no longer being
  sent (#3166). This is particularly noticeable in MQTT over TLS
  connections, because those usually takes longer than 1 second
  to finish and the timer would had chance to execute before connection
  is established

This commit checks the presense of `pesp_conn->proto.tcp` pointer
instead, which was allocated in the same place as the (old) `pesp_conn`
struct, and according to my test indeed fixes the above issue.
parent cb1b40ff
...@@ -753,7 +753,7 @@ void mqtt_socket_timer(void *arg) ...@@ -753,7 +753,7 @@ void mqtt_socket_timer(void *arg)
if(mud == NULL) if(mud == NULL)
return; return;
if(mud->connected == 0){ if(mud->pesp_conn.proto.tcp == NULL){
NODE_DBG("MQTT not connected\n"); NODE_DBG("MQTT not connected\n");
os_timer_disarm(&mud->mqttTimer); os_timer_disarm(&mud->mqttTimer);
return; return;
...@@ -1289,7 +1289,7 @@ static int mqtt_socket_close( lua_State* L ) ...@@ -1289,7 +1289,7 @@ static int mqtt_socket_close( lua_State* L )
espconn_status |= espconn_disconnect(&mud->pesp_conn); espconn_status |= espconn_disconnect(&mud->pesp_conn);
} }
} }
mud->connected = 0; mud->connected = false;
while (mud->mqtt_state.pending_msg_q) { while (mud->mqtt_state.pending_msg_q) {
msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment