WDT reset
Closed this issue · 4 comments
I was getting a constant WDT reset in my application due an endless loop in the function processRead(). There were two problems: an invalid message type (0) following a MQTT_MSG_TYPE_PINGRESP and length = 0 on MQTT_MSG_TYPE_PINGRESP. I don´t know what´s causing that conditions, but the function implementation can lead to an endless loop in case of an unexpected message content. I’m not sure, but I believe that the package may be discarded when a ping response is received. I also believe that´s important to limit the number of times that the loop can be performed. I don´t know if 10 times is enough, but it´s working for me.
To fix, I changed the code (bold) as bellow:
int MQTTClient::processRead()
{
**// change begin aonm
#define MAXREADRETRY 10 // limit of read retries
int retry = 0; // count read retries
// change end aonm**
*
*
*
case MQTT_MSG_TYPE_PINGRESP:
LOG("MQTT_MSG_TYPE_PINGRESP\r\n");
// Ignore
**// change begin aonm
return 0; //discard remaining data
// change end aonm**
break;
**// change begin aonm
default: // Trap invalid message types
LOG("Invalid message type %i\r\n", msg_type);
return 0;
// change end aonm**
}
if(_state.message_length < _state.message_length_read) {
_state.message_length_read -= _state.message_length;
_state.in_buffer += _state.message_length;
**// change begin aonm
retry++;
if (retry > MAXREADRETRY) {
return 0;
}
// change end aonm**
goto PROCESS_READ_AGAIN;
}
return 1;
}
I could find the same issue.
-Fatal exception 28(LoadProhibitedCause):
epc1=0x4020516c, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000016, depc=0x00000000
Exception (28):
epc1=0x4020516c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000016 depc=0x00000000
ctx: cont
sp: 3fff1330 end: 3fff15c0 offset: 01a0
stack>>>
3fff14d0: 0000007b 00000000 3fff03ec 40205133
3fff14e0: 3fff27e4 00000000 00000000 00000016
3fff14f0: 40203f95 00000016 00000016 40203fa2
3fff1500: 3fff287a 00000000 00000000 3fff38ec
3fff1510: 0000000f 00000000 3fff38d4 0000000f
3fff1520: 00000000 3fff1cd0 3fff03ec 40206eae
3fff1530: 0000000b 00000000 3fff03ec 40205361
3fff1540: 3fff0500 3fff0588 3fff1cd0 3fffdad0
3fff1550: 4020cc67 00000000 3fff03ec 3fff0590
3fff1560: 3fffdad0 3fff1cd0 3fff03ec 402054c4
3fff1570: 00000012 3fff1cd0 3fff0588 4020940e
3fff1580: 00000000 00000000 00000000 00000000
3fff1590: 00000000 00000000 00000001 40201ff1
3fff15a0: 3fffdad0 00000000 3fff0588 4020201c
3fff15b0: feefeffe feefeffe 3fff05a0 402031f8
<<<stack<<<
ets Jan 8 2013,rst cause:1, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
Same problem for me
Hello!
At first thank you Tuan PM for great piece of code
I experience the same problem and I try to figure out the reason. For me it looks like the faulty piece of code is here:
ESP8266MQTTClient/src/ESP8266MQTTClient.cpp
Line 473 in a36560f
if(_state.message_length < _state.message_length_read) {
_state.message_length_read -= _state.message_length;
_state.in_buffer += _state.message_length;
goto PROCESS_READ_AGAIN;
}
First|: the variable _state.message_length
seems to be used uninitialized (always reads zero). This causes infinite loop, because _state.message_length_read -= _state.message_length;
statement does not work and variable _state.message_length_read
has always the same value.
I would try to correct this issue, but i don't understand exact meaning of the variables _state.message_length
and _state.message_length_read
.
Second: is this piece of code _state.in_buffer += _state.message_length;
correct? Variable _state.in_buffer
is a pointer to dynamically allocated variable...
I think PROCESS_READ_AGAIN label in MQTTClient::processRead() may be misplaced, see PR #10 , this may fix!