Fixed an regression that MQTT client timer is disarmed prematurely when

connecting to server.

Inside af426d0315, 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.
This commit is contained in:
Datong Sun 2020-06-29 21:35:12 -07:00 committed by Nathaniel Wesley Filardo
parent cb1b40fffa
commit 95f5191cd3
1 changed files with 2 additions and 2 deletions

View File

@ -753,7 +753,7 @@ void mqtt_socket_timer(void *arg)
if(mud == NULL)
return;
if(mud->connected == 0){
if(mud->pesp_conn.proto.tcp == NULL){
NODE_DBG("MQTT not connected\n");
os_timer_disarm(&mud->mqttTimer);
return;
@ -1289,7 +1289,7 @@ static int mqtt_socket_close( lua_State* L )
espconn_status |= espconn_disconnect(&mud->pesp_conn);
}
}
mud->connected = 0;
mud->connected = false;
while (mud->mqtt_state.pending_msg_q) {
msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q)));