Skip to content

Crash once capture list is 'const' while responding by callback containing templates and extra headers #29

Closed
@lumapu

Description

@lumapu

Strange thing - I try to get a function for the user to download the core dump from the coredump partition. During loading the data I faced an issue and get contiously core-dumps.

I'm developing on a standard ESP32-Wroom32.

The code is slightly changed for debugging purposes. The buffer is initialized by a for-loop to better check for valid data. First the capture list was only by reference [&] but then I saw that my buffer (data[]) was modified. Then I changed the capture-list to const reference. This leads to a reproduceable state where the ESP reboots.

Code snippet
void getCoreDump(AsyncWebServerRequest *request) {
    const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");
    if (partition != NULL) {
        size_t size = partition->size;
        uint8_t *data = new uint8_t[size];

        // must be separate from transfer - otherwise it failes during read
        //if (ESP_OK != esp_partition_read(partition, 0, data, size))
        //    DPRINTLN(DBG_ERROR, F("can't read partition"));

        for(int i = 0; i < size; i++) {
            data[i] = i % 256;
        }

        AsyncWebServerResponse *response = request->beginResponse("application/octet-stream", size, [&data, &size](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
            if((index + maxLen) > size)
                maxLen = size - index;
            DPRINTLN(DBG_INFO, "maxLen: " + String(maxLen)); // without this, the ESP crahses!?
            memcpy(buffer, &data[index], maxLen);

            if((index + maxLen) == size)
                delete[] data;

            return maxLen;
        });

        response->addHeader("Content-Description", "File Transfer");
        response->addHeader("Content-Disposition", "attachment; filename=coredump.bin");
        request->send(response);
    } else {
        AsyncWebServerResponse *response = request->beginResponse(200, F("application/json; charset=utf-8"), "{}");
        request->send(response);
    }
}

once I call my ESP with [IP]/coredump the following stacktrace will be printed

Core Dump
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x4019bc71  PS      : 0x00060630  A0      : 0x8012908d  A1      : 0x3ffb30f0  
A2      : 0x8d11cd38  A3      : 0x00000006  A4      : 0x00000014  A5      : 0x0000ffff
A6      : 0x00000000  A7      : 0x00000001  A8      : 0x00000002  A9      : 0x0000ff00  
A10     : 0x00ff0000  A11     : 0x3ffdf898  A12     : 0x00000001  A13     : 0x00000002
A14     : 0x00000000  A15     : 0x00000001  SAR     : 0x00000019  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x8d11cd38  LBEG    : 0x4008a234  LEND    : 0x4008a24a  LCOUNT  : 0xffffffff


Backtrace: 0x4019bc6e:0x3ffb30f0 0x4012908a:0x3ffb3110 0x4012936a:0x3ffb3130 0x4012a956:0x3ffb3160 0x4012f97a:0x3ffb31d0 0x401339c6:0x3ffb3200 0x401248c5:0x3ffb3220

  #0  0x4019bc6e:0x3ffb30f0 in pbuf_clen at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/pbuf.c:824
  #1  0x4012908a:0x3ffb3110 in tcp_free_acked_segments at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp_in.c:1113
  #2  0x4012936a:0x3ffb3130 in tcp_receive at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp_in.c:1289 (discriminator 4)
  #3  0x4012a956:0x3ffb3160 in tcp_process at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp_in.c:987
      (inlined by) tcp_input at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp_in.c:438
  #4  0x4012f97a:0x3ffb31d0 in ip4_input at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/ipv4/ip4.c:803
  #5  0x401339c6:0x3ffb3200 in ethernet_input at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/netif/ethernet.c:186
  #6  0x401248c5:0x3ffb3220 in tcpip_thread_handle_msg at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:180
      (inlined by) tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:154




ELF file SHA256: e63468b51f8e834c

Rebooting...

Your documentation:
https://github.com/esphome/ESPAsyncWebServer/blob/main/README.md#respond-with-content-using-a-callback-containing-templates-and-extra-headers

Is there anything I'm missing? Don't know where the issue is related to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions