httpd_resp_send_chunk causing Guru Meditation Error

ruffle
Posts: 8
Joined: Tue Jul 31, 2018 6:46 am

httpd_resp_send_chunk causing Guru Meditation Error

Postby ruffle » Fri Apr 05, 2019 5:30 pm

I'm trying to download large(ish) files from my ESP32 over WiFi. A 100MB file is taking around 3 minutes which is very slow.

I've run the example wifi/iperf test (default sdkconfig) and that produces:

Code: Select all

esp32>    0-   3 sec       28.22 Mbits/sec
   3-   6 sec       34.60 Mbits/sec
   6-   9 sec       34.69 Mbits/sec
   9-  12 sec       34.82 Mbits/sec
  12-  15 sec       34.52 Mbits/sec
  15-  18 sec       34.65 Mbits/sec
  18-  21 sec       34.78 Mbits/sec
  21-  24 sec       34.95 Mbits/sec
  24-  27 sec       34.25 Mbits/sec
  27-  30 sec       34.56 Mbits/sec
  30-  33 sec       34.87 Mbits/sec
  33-  36 sec       32.03 Mbits/sec
  36-  39 sec       33.95 Mbits/sec
  39-  42 sec       34.73 Mbits/sec
  42-  45 sec       34.78 Mbits/sec
  45-  48 sec       34.91 Mbits/sec
  48-  51 sec       34.91 Mbits/sec
  51-  54 sec       34.73 Mbits/sec
  54-  57 sec       34.56 Mbits/sec
  57-  60 sec       34.56 Mbits/sec
   0-  60 sec       34.20 Mbits/sec
I (103595) iperf: iperf exit
which seems reasonable and should result in a ~30 second download for a 100MB file.

As I'm reading the file from an sd-card, I thought I'd try eliminating that as the source of slowness and just send a static buffer. However when I do that, I get the following "Guru Meditation Error: Core 1 panic'ed (LoadStoreError). Exception was unhandled." error.

Code: Select all

E (84988) ZX10R HTTP: Size: 8192
E (84995) ZX10R HTTP: Size: 16384
E (85008) ZX10R HTTP: Size: 24576
E (85024) ZX10R HTTP: Size: 32768
E (85048) ZX10R HTTP: Size: 40960
E (85081) ZX10R HTTP: Size: 49152
E (85114) ZX10R HTTP: Size: 57344
E (85155) ZX10R HTTP: Size: 65536
E (85210) ZX10R HTTP: Size: 73728
E (85265) ZX10R HTTP: Size: 81920
E (85330) ZX10R HTTP: Size: 90112
E (85399) ZX10R HTTP: Size: 98304
E (85460) ZX10R HTTP: Size: 106496
E (85530) ZX10R HTTP: Size: 114688
E (85603) ZX10R HTTP: Size: 122880
E (85681) ZX10R HTTP: Size: 131072
E (85765) ZX10R HTTP: Size: 139264
E (85867) ZX10R HTTP: Size: 147456
E (85978) ZX10R HTTP: Size: 155648
E (86089) ZX10R HTTP: Size: 163840
E (86208) ZX10R HTTP: Size: 172032
E (86317) ZX10R HTTP: Size: 180224
E (86429) ZX10R HTTP: Size: 188416
E (86543) ZX10R HTTP: Size: 196608
E (86673) ZX10R HTTP: Size: 204800
E (86820) ZX10R HTTP: Size: 212992
E (86975) ZX10R HTTP: Size: 221184
E (87129) ZX10R HTTP: Size: 229376
E (87283) ZX10R HTTP: Size: 237568
E (87449) ZX10R HTTP: Size: 245760
E (87616) ZX10R HTTP: Size: 253952
E (87768) ZX10R HTTP: Size: 262144
E (87955) ZX10R HTTP: Size: 270336
E (88115) ZX10R HTTP: Size: 278528
E (88295) ZX10R HTTP: Size: 286720
E (88467) ZX10R HTTP: Size: 294912
Guru Meditation Error: Core  1 panic'ed (LoadStoreError). Exception was unhandled.
Core 1 register dump:
PC      : 0x40092c2c  PS      : 0x00060f30  A0      : 0x80146ce0  A1      : 0x3ffd4e00  
0x40092c2c: memcpy at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/machine/xtensa/../../../../.././newlib/libc/machine/xtensa/memcpy.S:382

A2      : 0x3ffeac70  A3      : 0x400027af  A4      : 0x000003d5  A5      : 0x3ffeb044  
A6      : 0x8c609090  A7      : 0x8c609090  A8      : 0xc03530c0  A9      : 0x0b01b427  
A10     : 0x3ffeac0c  A11     : 0x00000003  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x0000000a  A15     : 0x3ffd4f20  SAR     : 0x00000018  EXCCAUSE: 0x00000003  
EXCVADDR: 0x400027af  LBEG    : 0x40092b99  LEND    : 0x40092bcd  LCOUNT  : 0x00000000  
0x40092b99: memcpy at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/machine/xtensa/../../../../.././newlib/libc/machine/xtensa/memcpy.S:291

0x40092bcd: memcpy at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/machine/xtensa/../../../../.././newlib/libc/machine/xtensa/memcpy.S:324


Backtrace: 0x40092c2c:0x3ffd4e00 0x40146cdd:0x3ffd4e10 0x40140490:0x3ffd4e60 0x401408b5:0x3ffd4e80 0x40145fe1:0x3ffd4ea0 0x400986dd:0x3ffd4ef0 0x400978f9:0x3ffd4f20 0x400970e5:0x3ffd4f40
0x40092c2c: memcpy at /home/jeroen/esp8266/esp32/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/machine/xtensa/../../../../.././newlib/libc/machine/xtensa/memcpy.S:382

0x40146cdd: tcp_write at /home/russell/esp/esp-idf/components/lwip/lwip/src/core/tcp_out.c:578

0x40140490: lwip_netconn_do_writemore at /home/russell/esp/esp-idf/components/lwip/lwip/src/api/api_msg.c:1447 (discriminator 6)

0x401408b5: sent_tcp at /home/russell/esp/esp-idf/components/lwip/lwip/src/api/api_msg.c:1447 (discriminator 6)

0x40145fe1: tcp_input at /home/russell/esp/esp-idf/components/lwip/lwip/src/core/tcp_in.c:402 (discriminator 1)

0x400986dd: ip4_input at /home/russell/esp/esp-idf/components/lwip/lwip/src/core/ipv4/ip4.c:119

0x400978f9: ethernet_input at /home/russell/esp/esp-idf/components/lwip/lwip/src/netif/ethernet.c:184

0x400970e5: tcpip_thread at /home/russell/esp/esp-idf/components/lwip/lwip/src/api/tcpip.c:483


Rebooting...

The code that generates this is:

Code: Select all

    #define SCRATCH_BUFSIZE  8192
    char chunk[SCRATCH_BUFSIZE +1];
    size_t chunksize;
    int i=0;
    bool no_disk_read = true;
    do {
        /* Read file in chunks into the scratch buffer */
        if( no_disk_read ) {
            i += SCRATCH_BUFSIZE;
            ESP_LOGE(TAG, "Size: %d",i);
            if ( i >= 105322328 ) i = 0;
            chunksize = i;
        } else {
            chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fp);
        }

        /* Send the buffer contents as HTTP response chunk */
        if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
            fclose(fp);
            ESP_LOGE(TAG, "File sending failed!");
            /* Abort sending file */
            httpd_resp_sendstr_chunk(req, NULL);
            /* Send error message with status code */
            httpd_resp_set_status(req, "500 Server Error");
            httpd_resp_sendstr(req, "Failed to send file!");
            goto RET;
        }

        /* Keep looping till the whole file is sent */
    } while (chunksize != 0);


I don't get the Guru Meditation Error when no_disk_read is set to false but the download is sloooooooooow :(

This is compiled with "ESP-IDF v3.3-beta1-430-g7cdd19fb6-dirty".

Does anyone have any ideas as to why it's triggering this error? or how I can speed up Wifi Downloads?

Thanks in Advance.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 106 guests