esp_netif_receive eating all my ram (SLIP protocol) (IDFGH-4141)
Posted: Tue Oct 20, 2020 10:00 am
Hi there,
We're using SLIP protocol to communicate an esp32 device with a mcu and all seems to be ok, but we're having reboots from time to time depending on the data received by the esp32, caused by an abort on an internall memory allocation, so there's a memory leak somewhere...
We've also included a heap memory tracking task to determine from where the memory leak comes from, and we found our slip reception task is consuming all the memory for some reason...
As the task is pretty simple (no dynamic memory allocation) we determined the problem was wit esp_netif_receive function.
We started from the slip_udp example (examples/protocols/slip/slip_udp/) without much changes, we've only changed the receiving task to make it more robust (managing fifo overtflows, etc...).
¿Any clue about how to solve/trace the issue?
P.S.: Here is our receiving task, in case you wonder what we've changed
P.S.2: Here is the error message it give us
We're using SLIP protocol to communicate an esp32 device with a mcu and all seems to be ok, but we're having reboots from time to time depending on the data received by the esp32, caused by an abort on an internall memory allocation, so there's a memory leak somewhere...
We've also included a heap memory tracking task to determine from where the memory leak comes from, and we found our slip reception task is consuming all the memory for some reason...
As the task is pretty simple (no dynamic memory allocation) we determined the problem was wit esp_netif_receive function.
We started from the slip_udp example (examples/protocols/slip/slip_udp/) without much changes, we've only changed the receiving task to make it more robust (managing fifo overtflows, etc...).
¿Any clue about how to solve/trace the issue?
P.S.: Here is our receiving task, in case you wonder what we've changed
Code: Select all
static void esp_slip_modem_uart_rx_task(void *arg) {
uart_event_t event;
esp_slip_modem_t *slip_modem = (esp_slip_modem_t *) arg;
int len;
while (slip_modem->running == true) {
if(xQueueReceive(slip_modem->uart.uart_queue, (void * )&event, 1)) {
switch(event.type) {
case UART_DATA:
// Read data from the UART
len = uart_read_bytes(slip_modem->uart.uart_dev, slip_modem->buffer, slip_modem->buffer_len, 1);
if (len > 0) {
// Ensure null termination
slip_modem->buffer[len] = '\0';
esp_netif_receive(slip_modem->base.netif, slip_modem->buffer, len, NULL);
}
if (len < 0) {
// Asume error and clear everything
uart_flush_input(slip_modem->uart.uart_dev);
xQueueReset(slip_modem->uart.uart_queue);
}
break;
case UART_FIFO_OVF:
case UART_BUFFER_FULL:
uart_flush_input(slip_modem->uart.uart_dev);
xQueueReset(slip_modem->uart.uart_queue);
break;
case UART_FRAME_ERR:
default:
break;
}
} else {
vTaskDelay(pdMS_TO_TICKS(1));
}
}
vTaskDelete(NULL);
}
Code: Select all
Memory allocation failed
Backtrace:0x4008e9e6:0x3ffd0d60 0x4008f049:0x3ffd0d80 0x400f60ab:0x3ffd0da0 0x4008565b:0x3ffd0dc0 0x40085738:0x3ffd0df0 0x40085b5a:0x3ffd0e10 0x40085b99:0x3ffd0e50 0x40151c24:0x3ffd0e70 0x40151cc2:0x3ffd0e90 0x40151d30:0x3ffd0eb0 0x400941f4:0x3ffd0ed0 0x4015c3fb:0x3ffd0ef0 0x4015c4c7:0x3ffd0f10 0x4015c623:0x3ffd0f30 0x4014ec65:0x3ffd0f50 0x4017d571:0x3ffd0f70 0x400f7065:0x3ffd0f90
0x4008e9e6: panic_abort at /home/desarrollo/devel/esp32/esp-idf/components/esp_system/panic.c:360
0x4008f049: esp_system_abort at /home/desarrollo/devel/esp32/esp-idf/components/esp_system/system_api.c:104
0x400f60ab: heap_caps_alloc_failed at /home/desarrollo/devel/esp32/esp-idf/components/heap/heap_caps.c:67
0x4008565b: heap_caps_malloc at /home/desarrollo/devel/esp32/esp-idf/components/heap/heap_caps.c:155
0x40085738: heap_caps_malloc_default at /home/desarrollo/devel/esp32/esp-idf/components/heap/heap_caps.c:187
0x40085b5a: trace_malloc at /home/desarrollo/devel/esp32/esp-idf/components/heap/include/heap_trace.inc:95
0x40085b99: __wrap_malloc at /home/desarrollo/devel/esp32/esp-idf/components/heap/include/heap_trace.inc:157
0x40151c24: mem_malloc at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/core/mem.c:237
0x40151cc2: do_memp_malloc_pool at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/core/memp.c:254
0x40151d30: memp_malloc at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/core/memp.c:350 (discriminator 2)
0x400941f4: pbuf_alloc at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/core/pbuf.c:247
0x4015c3fb: slipif_rxbyte at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/netif/slipif.c:265 (discriminator 4)
0x4015c4c7: slipif_rxbyte_enqueue at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/netif/slipif.c:494
0x4015c623: slipif_received_bytes at /home/desarrollo/devel/esp32/esp-idf/components/lwip/lwip/src/netif/slipif.c:555 (discriminator 3)
0x4014ec65: esp_netif_lwip_slip_input at /home/desarrollo/devel/esp32/esp-idf/components/esp_netif/lwip/esp_netif_lwip_slip.c:165 (discriminator 3)
0x4017d571: esp_netif_receive at /home/desarrollo/devel/esp32/esp-idf/components/esp_netif/lwip/esp_netif_lwip.c:803
0x400f7065: esp_slip_modem_uart_rx_task at /home/desarrollo/devel/esp32/eth2slip/main/src/driver/slip_modem.c:221