Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash (heap corruption) when rapidly refreshing the web page #394

Closed
me21 opened this issue Aug 5, 2018 · 125 comments
Closed

Crash (heap corruption) when rapidly refreshing the web page #394

me21 opened this issue Aug 5, 2018 · 125 comments
Labels

Comments

@me21
Copy link
Contributor

me21 commented Aug 5, 2018

I've constructed an example which shows the crashes. Just connect to the ESP32 access point, open its default web page in browser, and hit F5 several times rapidly.
You should see a crash like this: CORRUPT HEAP: Bad head at 0x3f801240. Expected 0xabba1234 got 0x3f801334<CR><LF> assertion "head != NULL" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c", line 205, function: multi_heap_free.

I have attached the project which should trigger the bug. I use ESP32-WROVER for this, if it matters.

espasyncwebserverissue.zip

@me21 me21 changed the title Crash when rapidly refreshing the web page Crash (heap corruption) when rapidly refreshing the web page Aug 5, 2018
@me21
Copy link
Contributor Author

me21 commented Aug 7, 2018

Some stack traces:

stack:
0x40091848: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x40091a4b: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x400dd12f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x40091515: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c:306
0x400868e2: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:123
0x40088aa5: _free_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c:42
0x400ffd96: tcp_close_shutdown at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c:835
0x400ffe5e: tcp_close at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c:835
0x4012bb4d: _tcp_close_api(tcpip_api_call*) at AsyncTCP.cpp:?
0x400fca19: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/api/tcpip.c:474
stack:
0x40091848: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x40091a4b: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x400dd12f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x4009156d: multi_heap_realloc at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c:306
0x40086948: heap_caps_realloc at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:123
0x400869a6: heap_caps_realloc_default at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:123
0x40088ab5: _realloc_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c:47
0x400d9282: String::changeBuffer(unsigned int) at ??:?
0x400d92e5: String::reserve(unsigned int) at ??:?
0x400d9456: String::concat(char const*, unsigned int) at ??:?
0x400d9499: String::concat(char const*) at ??:?
0x400d56b5: AsyncWebServerRequest::_onData(void*, unsigned int) at ??:?
0x400d5945: std::_Function_handler<void (void*, AsyncClient*, void*, unsigned int), AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer*, AsyncClient*)::{lambda(void*, AsyncClient*, void*, unsigned int)#7}>::_M_invoke(std::_Any_data const&, void*&&, AsyncClient*&&, std::_Any_data const&, unsigned int&&) at WebRequest.cpp:?
0x4012c1a5: AsyncClient::_recv(tcp_pcb*, pbuf*, signed char) at ??:?
0x4012c411: _async_service_task(void*) at AsyncTCP.cpp:?
stack:
0x40091848: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x40091a4b: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x400dd12f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x40091515: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c:306
0x400868e2: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:123
0x40088aa5: _free_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c:42
0x400d9252: String::~String() at ??:?
0x400d6a6d: AsyncWebServerResponse::~AsyncWebServerResponse() at ??:?
0x400d6a7e: AsyncWebServerResponse::~AsyncWebServerResponse() at ??:?
0x400d5dc2: AsyncWebServerRequest::~AsyncWebServerRequest() at ??:?
0x400d7d6d: AsyncWebServer::_handleDisconnect(AsyncWebServerRequest*) at ??:?
0x400d36d2: AsyncWebServerRequest::_onDisconnect() at ??:?
0x400d36e1: std::_Function_handler<void (void*, AsyncClient*), AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer*, AsyncClient*)::{lambda(void*, AsyncClient*)#5}>::_M_invoke(std::_Any_data const&, void*&&, AsyncClient*&&) at WebRequest.cpp:?
0x4012c056: std::function<void (void*, AsyncClient*)>::operator()(void*, AsyncClient*) const at ??:?
0x4012c337: AsyncClient::_error(signed char) at ??:?
0x4012c447: _async_service_task(void*) at AsyncTCP.cpp:?

@me21
Copy link
Contributor Author

me21 commented Aug 7, 2018

Firefox 61.0.1 x64 doesn't cause crashes, whereas Chrome 68.0.3440.84 x64 does.

@me-no-dev
Copy link
Owner

First and last seem to be related to trying to free something that is already freed, though the second one looks similar. Could be related to “Connection: close” header for web sockets

@me21
Copy link
Contributor Author

me21 commented Aug 7, 2018

Could you please tell more details? Can I fix it as a user of the library, or it's you who should fix it?

There is no active websocket in the example, by the way, although the browser tries to connect it. I will try to remove it from the webpage code and report back.

@me21
Copy link
Contributor Author

me21 commented Aug 7, 2018

No difference after removing websocket code from stored web page.

I've noticed that "Connection: close" is sent with every response, not just web sockets. Is it a problem?

@me21
Copy link
Contributor Author

me21 commented Aug 12, 2018

Looks like a duplicate of #324. But I'm not sure.

@me-no-dev
Copy link
Owner

pull the latest changes for AsyncTCP and the WebServer. I just pushed a probable fix for all of those errors

@emptynick
Copy link

emptynick commented Aug 16, 2018

Looks a bit better, but still throwing the exception from time to time:

CORRUPT HEAP: Bad head at 0x3ffdf6c8. Expected 0xabba1234 got 0x3ffdf79c
assertion "head != NULL" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning
.c", line 205, function: multi_heap_free
abort() was called at PC 0x400ecb7f on core 0

Backtrace: 0x4009034c:0x3ffb7080 0x4009054f:0x3ffb70a0 0x400ecb7f:0x3ffb70c0 0x40090019:0x3ffb70f0 0x4008534e:0x3ffb7110 0x4
0087515:0x3ffb7130 0x4000bec7:0x3ffb7150 0x4010e99a:0x3ffb7170 0x4010ea62:0x3ffb7190 0x4013ba6d:0x3ffb71b0 0x4010a9a9:0x3ffb
71d0

Decoded

Decoding 11 results
0x400ecb7f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c line 63 (discriminator 8)
0x4009034c: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 649
0x4009054f: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 649
0x400ecb7f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c line 63 (discriminator 8)
0x40090019: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c line 306
0x4008534e: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c line 123
0x4010e99a: tcp_close_shutdown at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c line 225
0x4010ea62: tcp_close at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c line 305
0x4013ba6d: _tcp_close_api(tcpip_api_call*) at AsyncTCP.cpp line ?
0x4010a9a9: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/api/tcpip.c line 474

One thing I noticed: After it crashed once I cant get it to crash again. Am I seeing things?

@me-no-dev
Copy link
Owner

it's just really hard to crash it. I know why it happens but I don't have a final fix yet... if you use the server normally, all is fine. Crashes when you refresh your browser while it's loading (that causes premature closing of connections and opening new ones)

@bbasil2012
Copy link

It seems that it works better than before.
Uptime is more than 1 hour

@bbasil2012
Copy link

3 hours of uptime and crash:
CORRUPT HEAP: Bad head at 0x3ffe1c70. Expected 0xabba1234 got 0x3ffe1ccc
assertion "head != NULL" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/./multi_heap_poisoning.c", line 199, function: multi_heap_free
abort() was called at PC 0x400e8e53 on core 1

Backtrace: 0x4008888c:0x3ffd9e70 0x4008898b:0x3ffd9e90 0x400e8e53:0x3ffd9eb0 0x400885b5:0x3ffd9ee0 0x40084306:0x3ffd9f00 0x40084889:0x3ffd9f20 0x4000bec7:0x3ffd9f40 0x40105ff1:0x3ffd9f60 0x401060b3:0x3ffd9f80 0x400de7cd:0x3ffd9fa0 0x40102675:0x3ffd9fc0

Rebooting...

@me-no-dev
Copy link
Owner

please decode any backtrace that you post ;)

I am still hunting causes for bad heap... I am getting to the point where they make no sense... I am checking everything for accessing already freed resources (that is usually what causes the above) but i am starting to fail. There are a few fixes to both AsyncTCP and the WebServer, make sure you have them all :)

@emptynick
Copy link

Dont know if its helpful for you that we post more and more exceptions, but here you go:

Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x4016326f  PS      : 0x00060830  A0      : 0x8013b821  A1      : 0x3ffde670
A2      : 0x02a40742  A3      : 0x00000000  A4      : 0x00060820  A5      : 0x3ffde710
A6      : 0x3ffe0c98  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffde680
A10     : 0x3ffd4fc8  A11     : 0x3ffdfa54  A12     : 0x4c400000  A13     : 0x00000000

A14     : 0x00000000  A15     : 0x00000001  SAR     : 0x0000000a  EXCCAUSE: 0x0000001d
EXCVADDR: 0x02a40772  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff

Backtrace: 0x4016326f:0x3ffde670 0x4013b81e:0x3ffde690 0x4013bb1c:0x3ffde6d0 0x4013bb8f:0x3ffde700

Decoded

0x4016326f: tcp_arg at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c line 1652
0x4016326f: tcp_arg at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c line 1652
0x4013b81e: AsyncClient::_close() at ?? line ?
0x4013bb1c: AsyncClient::_poll(tcp_pcb*) at ?? line ?
0x4013bb8f: _async_service_task(void*) at AsyncTCP.cpp line ?

@me21
Copy link
Contributor Author

me21 commented Aug 19, 2018

Is it possible that the heap is already silently corrupted earlier and the backtrace doesn't show the root cause?
Also, is it possible that ESP32 memory manager is not thread safe? Then you cannot fix it at library level :(

@me-no-dev
Copy link
Owner

I went back and fourth and covered everything that I can come up with. Given that exceptions happen even when running normal web server code (no web sockets or service events) and given that the server runs in a single thread... I am totally out of ideas. I double checked, triple checked... nothing if freed twice or accessed after free, so why the corruption...? Poked @igrr for ideas (no response yet)... no idea where to go next... I have traced JTAGed and done everything i can come up so far to try and figure out what chain of events might cause this... nothing. BTW when I use the server normally (no crazy reloads or else) everything is fine. I can see how there can be some issues with the web sockets and I will patch those down the line, but the web server itself... i see nothing

@me-no-dev
Copy link
Owner

BTW I could not crash the server for pages that run from flash (progmem and not spiffs)

@me21
Copy link
Contributor Author

me21 commented Aug 20, 2018

Thanks, that's an interesting idea! I will check and report back. Maybe it's SPIFFS who corrupts the heap, and web server is just poor victim.

@bbasil2012
Copy link

I communicate with the server rendered as chrome app.
This chorme-app communicate with the server only through rest-api
SPIFS is used only at startup to read configuration files.
Thus, the server does not serve any files located on the SPIFS via http
But it is still crashes ...

@me-no-dev
Copy link
Owner

@bbasil2012 this with the latest tcp and server libs?

@bbasil2012
Copy link

@me-no-dev Yes

@me21
Copy link
Contributor Author

me21 commented Aug 23, 2018

I've found the following paragraph at https://arduino-esp8266.readthedocs.io/en/latest/faq/a02-my-esp-crashes.html

Asynchronous Callbacks
Asynchronous CBs, such as for the Ticker or ESPAsync* libs, have looser restrictions than ISRs, but some restrictions still apply. It is not possible to execute delay() or yield() from an asynchronous callback. Timing is not as tight as an ISR, but it should remain below a few milliseconds. This is a guideline. The hard timing requirements depend on the WiFi configuration and amount of traffic. In general, the CPU must not be hogged by the user code, as the longer it is away from servicing the WiFi stack, the more likely that memory corruption can happen.

Wait, so the memory corruption can happen by simply staying too long in the asynchronous callback??

Or this applies to ESP8266 only, and not to ESP32?

@HenrikSte
Copy link

HenrikSte commented Aug 24, 2018

Folks,

(I am totally new to github - bear with me, willing to learn)

I am getting a similar (same?) issue with an almost unmodified example code.
I do not need to run the refresh at high speed, once every 3 seconds is enough to get it to eventually crash.

//
// A simple server implementation showing how to:
//  * serve static messages
//  * read GET and POST parameters
//  * handle missing pages / 404s
//


#include <FreeRTOS.h>
#include <AsyncTCP.h>
//#include <Hash.h>
#include <ESPAsyncWebServer.h>
AsyncWebServer server(80);

const char* ssid = "MSIDEMO";
const char* password = "msitest123";

const char* PARAM_MESSAGE = "message";

void notFound(AsyncWebServerRequest *request) {
    request->send(404, "text/plain", "Not found");
}


void setup() {

    Serial.begin(115200);
    WiFi.mode(WIFI_STA);

    IPAddress _ip,_gw,_sn;
    _ip.fromString("192.168.150.252");
    _gw.fromString("10.0.1.1");
    _sn.fromString("255.255.255.0"); 

    Serial.println(F("Connecting as wifi client..."));

  // check if we've got static_ip settings, if we do, use those.
    WiFi.config(_ip, _gw, _sn);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.printf("WiFi Failed!\n");
        return;
    }

    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());
    Serial.print("Hostname: ");
    Serial.println(WiFi.getHostname());

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        request->send(200, "text/plain", "Hello, world");
    });

    // Send a GET request to <IP>/get?message=<message>
    server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
        String message;
        if (request->hasParam(PARAM_MESSAGE)) {
            message = request->getParam(PARAM_MESSAGE)->value();
        } else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, GET: " + message);
    });

    // Send a POST request to <IP>/post with a form field message set to <message>
    server.on("/post", HTTP_POST, [](AsyncWebServerRequest *request){
        String message;
        if (request->hasParam(PARAM_MESSAGE, true)) {
            message = request->getParam(PARAM_MESSAGE, true)->value();
        } else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, POST: " + message);
    });

    server.on("/GetNextMessage", HTTP_GET, [](AsyncWebServerRequest *request){
      if (request)
      {
        Serial.print("GetNextMessage");
        String response;
        //toggleLED();
        response = "<NoMessage/>";
        request->send(200, "text/plain", response);
      }
      else
      {
        Serial.println("request is NULL");
      }
      Serial.println(".");

    });

    server.onNotFound(notFound);

    server.begin();
}

void loop() {
}

Some of my exceptions:

Exception Cause: Not found

0x4013a1e7: AsyncServer::_accept(tcp_pcb*, signed char) at ??:?
0x4000c349: ?? ??:0
0x4000c36b: ?? ??:0
0x4013a1e7: AsyncServer::_accept(tcp_pcb*, signed char) at ??:?
0x4013a2b0: AsyncServer::_s_accept(void*, tcp_pcb*, signed char) at ??:?
0x40109cf9: tcp_process at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp_in.c:792 (discriminator 1)
0x4010a7ed: tcp_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp_in.c:357
0x4010f38e: ip4_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/ipv4/ip4.c:711
0x40115df6: ethernet_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/netif/ethernet.c:176
0x40103bf9: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/api/tcpip.c:474

(this one is rare, the other are the ususal ones)

Exception Cause: Not found

0x400da19f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x4008f6f4: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x4008f8f7: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x400da19f: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x4008f3c1: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c:306
0x40084782: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:123
0x40086949: _free_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c:42
0x4000bec7: ?? ??:0
0x400f3bde: tcp_close_shutdown at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c:835
0x400f3ca6: tcp_close at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c:835
0x4011f7c9: _tcp_close_api(tcpip_api_call*) at AsyncTCP.cpp:?
0x400f0875: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/api/tcpip.c:474
Exception Cause: Not found

0x4011fdc7: AsyncServer::_accept(tcp_pcb*, signed char) at ??:?
0x4000c349: ?? ??:0
0x4000c36b: ?? ??:0
0x4011fdc7: AsyncServer::_accept(tcp_pcb*, signed char) at ??:?
0x4011fe90: AsyncServer::_s_accept(void*, tcp_pcb*, signed char) at ??:?
0x400f5975: tcp_process at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp_in.c:792 (discriminator 1)
0x400f6469: tcp_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp_in.c:357
0x400fafde: ip4_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/ipv4/ip4.c:711
0x40100e02: ethernet_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/netif/ethernet.c:176
0x400f089d: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/api/tcpip.c:474
0x400da29b: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x4008f6f4: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x4008f8f7: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c:649
0x400da29b: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)
0x4008eb03: get_next_block at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap.c:377
 (inlined by) assert_valid_block at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap.c:164
0x4008ee53: multi_heap_free_impl at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap.c:377
0x4008f3ca: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c:306
0x40084782: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:123
0x40086949: _free_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c:42
0x4000bec7: ?? ??:0
0x401200f3: _async_service_task(void*) at AsyncTCP.cpp:?

@HenrikSte
Copy link

HenrikSte commented Aug 24, 2018

One additional note: sometimes I get a different behavior.
Not sure if that has the same cause...

E (23754) wifi: lmac.c lmacProcessTxRtsError 1637

Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 0)
Tasks currently running:
CPU 0: wifi
CPU 1: loopTask
Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 0)
Tasks currently running:
CPU 0: wifi
CPU 1: loopTask
Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 0)
Tasks currently running:
CPU 0: wifi
CPU 1: loopTask

[ repeating forever]

@acris5
Copy link

acris5 commented Aug 31, 2018

Also got many errors while serving page with many resources from SPIFFS and rapidly refreshing ajax:

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

CORRUPT HEAP: Bad head at 0x3ffbfdbc. Expected 0xabba1234 got 0x3ffbfef8
assertion "head != NULL" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c", line 205, function: multi_heap_free
abort() was called at PC 0x400e3e8f on core 1

Backtrace: 0x4008f7d8:0x3ffb6900 0x4008f9db:0x3ffb6920 0x400e3e8f:0x3ffb6940 0x4008f4a5:0x3ffb6970 0x40084866:0x3ffb6990 0x40086a2d:0x3ffb69b0 0x4000bec7:0x3ffb69d0 0x40109bea:0x3ffb69f0 0x40109cb2:0x3ffb6a10 0x40150825:0x3ffb6a30 0x40105cf1:0x3ffb6a50

tcp_close_shutdown + 306 in section .flash.text
(gdb) info symbol 0x40109cb2
tcp_close + 26 in section .flash.text
(gdb) info symbol 0x40150825
_tcp_close_api(tcpip_api_call*) + 5 in section .flash.text
(gdb) info symbol 0x4015082
No symbol matches 0x4015082.
(gdb) info symbol 0x40105cf1
tcpip_thread + 81 in section .flash.text

Most of errors gone when uncommented: #define DEBUGF(...) Serial.printf(VA_ARGS)

but still have problem uploading multipart data with HTTP_POST request (only get first three parts of data than fails)

server.on("/update.cgi", HTTP_POST, [](AsyncWebServerRequest *request) {},
        [](AsyncWebServerRequest *request, const String filename, size_t index, uint8_t *data, size_t len, bool final){}, 
        HTTPExecutePostUpdate);
UPDATE: len, index ,total
1436 0 79788
UPDATE: len, index ,total
1436 1436 79788
UPDATE: len, index ,total
1436 2872 79788

assertion "new_rcv_ann_wnd <= 0xffff" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/core/tcp.c", line 630, function: tcp_update_rcv_ann_wnd
abort() was called at PC 0x400e064b on core 1

Backtrace: 0x4008f7d8:0x3ffb6980 0x4008f9db:0x3ffb69a0 0x400e064b:0x3ffb69c0 0x40104546:0x3ffb69f0 0x401045ce:0x3ffb6a10 0x4014a6f5:0x3ffb6a30 0x40101c95:0x3ffb6a50
Rebooting...

(gdb) info symbol 0x40104546
tcp_update_rcv_ann_wnd + 90 in section .flash.text
(gdb) info symbol 0x401045ce
tcp_recved + 122 in section .flash.text
(gdb) info symbol 0x4014a6f5
_tcp_recved_api(tcpip_api_call*) + 13 in section .flash.text
(gdb) info symbol 0x40101c95
tcpip_thread + 81 in section .flash.text

problem was because of sending 200 for every chunk of data. Seems that works only if send 200 on end of data.

@davidgevorgian
Copy link

davidgevorgian commented Oct 10, 2018

Simple bin upload. "Update.write"- upload only three parts, then crash...

Part of code

server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
request->send(200, "text/plain","DONE...");
},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final)

Update.write(data, len)

DEBUG LOG

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1496
load:0x40078000,len:8596
load:0x40080400,len:6980
entry 0x400806f4
Update Start: ver0.1a.ino.esp32.bin
Start write: 1271 bytes
Pack addr: 0x3ffca91c
Start write: 1436 bytes
Pack addr: 0x3ffca91c
Start write: 1436 bytes
Pack addr: 0x3ffca91c
abort() was called at PC 0x400e05a9 on core 1

Backtrace: 0x4008f9c4:0x3ffc9b80 0x4008fb99:0x3ffc9ba0 0x400e05a9:0x3ffc9bc0 0x400819fb:0x3ffc9be0 0x400d8605:0x3ffc9c00 0x400d817c:0x3ffc9c20 0x400d8361:0x3ffc9c40 0x400d1d25:0x3ffc9c60 0x4014d0c3:0x3ffc9c90 0x4014cfea:0x3ffc9ce0 0x400d481a:0x3ffc9d10 0x400d5bae:0x3ffc9d70 0x400d5d79:0x3ffc9dc0 0x400d3739:0x3ffc9de0 0x400d3782:0x3ffc9e20 0x400d3a22:0x3ffc9e40 0x4008ba0d:0x3ffc9e70

Exception Decoder
Decoding stack results
0x4008f9c4: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155
0x4008fb99: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170
0x400e05a9: is_safe_write_address at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/flash_ops.c line 118
0x400819fb: spi_flash_erase_sector at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/flash_ops.c line 196
0x400d8605: EspClass::flashEraseSector(unsigned int) at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\cores\esp32\Esp.cpp line 243
0x400d817c: UpdateClass::_writeBuffer() at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\libraries\Update\src\Updater.cpp line 185
0x400d8361: UpdateClass::write(unsigned char*, unsigned int) at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\libraries\Update\src\Updater.cpp line 290
0x400d1d25: std::_Function_handler >::_M_invoke(const std::_Any_data &, , const String &, , , , ) at D:\DAVID_FILES\Desktop\Arduino_Projects\AQUARIUM\ESP32\HTTP_Async\ver0.1a/ver0.1a.ino line 70
0x4014d0c3: AsyncCallbackWebHandler::handleUpload(AsyncWebServerRequest*, String const&, unsigned int, unsigned char*, unsigned int, bool) at c:\users\david\documents\arduino\hardware\espressif\esp32\tools\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x4014cfea: AsyncWebServerRequest::_handleUploadByte(unsigned char, bool) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 370
0x400d481a: AsyncWebServerRequest::_parseMultipartPostByte(unsigned char, bool) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 402
0x400d5bae: AsyncWebServerRequest::_onData(void*, unsigned int) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 137
0x400d5d79: std::_Function_handler >::_M_invoke(const std::_Any_data &, , , , ) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 75
0x400d3739: AsyncClient::_recv(tcp_pcb*, pbuf*, signed char) at c:\users\david\documents\arduino\hardware\espressif\esp32\tools\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x400d3782: AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, signed char) at C:\Users\David\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 977
0x400d3a22: _async_service_task(void*) at C:\Users\David\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 148
0x4008ba0d: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 141

NOTE:
I found. And problem solved by SPIFFS.format().

@ms4905
Copy link

ms4905 commented Dec 24, 2018

Simple bin upload. "Update.write"- upload only three parts, then crash...

Part of code

server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
request->send(200, "text/plain","DONE...");
},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final)

Update.write(data, len)

DEBUG LOG

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1496
load:0x40078000,len:8596
load:0x40080400,len:6980
entry 0x400806f4
Update Start: ver0.1a.ino.esp32.bin
Start write: 1271 bytes
Pack addr: 0x3ffca91c
Start write: 1436 bytes
Pack addr: 0x3ffca91c
Start write: 1436 bytes
Pack addr: 0x3ffca91c
abort() was called at PC 0x400e05a9 on core 1

Backtrace: 0x4008f9c4:0x3ffc9b80 0x4008fb99:0x3ffc9ba0 0x400e05a9:0x3ffc9bc0 0x400819fb:0x3ffc9be0 0x400d8605:0x3ffc9c00 0x400d817c:0x3ffc9c20 0x400d8361:0x3ffc9c40 0x400d1d25:0x3ffc9c60 0x4014d0c3:0x3ffc9c90 0x4014cfea:0x3ffc9ce0 0x400d481a:0x3ffc9d10 0x400d5bae:0x3ffc9d70 0x400d5d79:0x3ffc9dc0 0x400d3739:0x3ffc9de0 0x400d3782:0x3ffc9e20 0x400d3a22:0x3ffc9e40 0x4008ba0d:0x3ffc9e70

Exception Decoder
Decoding stack results
0x4008f9c4: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155
0x4008fb99: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170
0x400e05a9: is_safe_write_address at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/flash_ops.c line 118
0x400819fb: spi_flash_erase_sector at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/flash_ops.c line 196
0x400d8605: EspClass::flashEraseSector(unsigned int) at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\cores\esp32\Esp.cpp line 243
0x400d817c: UpdateClass::_writeBuffer() at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\libraries\Update\src\Updater.cpp line 185
0x400d8361: UpdateClass::write(unsigned char*, unsigned int) at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\libraries\Update\src\Updater.cpp line 290
0x400d1d25: std::_Function_handler >::_M_invoke(const std::_Any_data &, , const String &, , , , ) at D:\DAVID_FILES\Desktop\Arduino_Projects\AQUARIUM\ESP32\HTTP_Async\ver0.1a/ver0.1a.ino line 70
0x4014d0c3: AsyncCallbackWebHandler::handleUpload(AsyncWebServerRequest*, String const&, unsigned int, unsigned char*, unsigned int, bool) at c:\users\david\documents\arduino\hardware\espressif\esp32\tools\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x4014cfea: AsyncWebServerRequest::_handleUploadByte(unsigned char, bool) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 370
0x400d481a: AsyncWebServerRequest::_parseMultipartPostByte(unsigned char, bool) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 402
0x400d5bae: AsyncWebServerRequest::_onData(void*, unsigned int) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 137
0x400d5d79: std::_Function_handler >::_M_invoke(const std::_Any_data &, , , , ) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 75
0x400d3739: AsyncClient::_recv(tcp_pcb*, pbuf*, signed char) at c:\users\david\documents\arduino\hardware\espressif\esp32\tools\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x400d3782: AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, signed char) at C:\Users\David\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 977
0x400d3a22: _async_service_task(void*) at C:\Users\David\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 148
0x4008ba0d: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 141

NOTE:
I found. And problem solved by SPIFFS.format().

But where did you put the SPIFFS.format() ?
I tried it but it seems to crash anyway.

@davidgevorgian
Copy link

Simple bin upload. "Update.write"- upload only three parts, then crash...
Part of code
server.on("/update", HTTP_POST, [](AsyncWebServerRequest request){
request->send(200, "text/plain","DONE...");
},[](AsyncWebServerRequest request, String filename, size_t index, uint8_t data, size_t len, bool final)
Update.write(data, len)
DEBUG LOG
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1496
load:0x40078000,len:8596
load:0x40080400,len:6980
entry 0x400806f4
Update Start: ver0.1a.ino.esp32.bin
Start write: 1271 bytes
Pack addr: 0x3ffca91c
Start write: 1436 bytes
Pack addr: 0x3ffca91c
Start write: 1436 bytes
Pack addr: 0x3ffca91c
abort() was called at PC 0x400e05a9 on core 1
Backtrace: 0x4008f9c4:0x3ffc9b80 0x4008fb99:0x3ffc9ba0 0x400e05a9:0x3ffc9bc0 0x400819fb:0x3ffc9be0 0x400d8605:0x3ffc9c00 0x400d817c:0x3ffc9c20 0x400d8361:0x3ffc9c40 0x400d1d25:0x3ffc9c60 0x4014d0c3:0x3ffc9c90 0x4014cfea:0x3ffc9ce0 0x400d481a:0x3ffc9d10 0x400d5bae:0x3ffc9d70 0x400d5d79:0x3ffc9dc0 0x400d3739:0x3ffc9de0 0x400d3782:0x3ffc9e20 0x400d3a22:0x3ffc9e40 0x4008ba0d:0x3ffc9e70
Exception Decoder
Decoding stack results
0x4008f9c4: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155
0x4008fb99: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170
0x400e05a9: is_safe_write_address at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/flash_ops.c line 118
0x400819fb: spi_flash_erase_sector at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/flash_ops.c line 196
0x400d8605: EspClass::flashEraseSector(unsigned int) at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\cores\esp32\Esp.cpp line 243
0x400d817c: UpdateClass::_writeBuffer() at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\libraries\Update\src\Updater.cpp line 185
0x400d8361: UpdateClass::write(unsigned char
, unsigned int) at C:\Users\David\Documents\Arduino\hardware\espressif\esp32\libraries\Update\src\Updater.cpp line 290
0x400d1d25: std::_Function_handler >::_M_invoke(const std::_Any_data &, , const String &, , , , ) at D:\DAVID_FILES\Desktop\Arduino_Projects\AQUARIUM\ESP32\HTTP_Async\ver0.1a/ver0.1a.ino line 70
0x4014d0c3: AsyncCallbackWebHandler::handleUpload(AsyncWebServerRequest
, String const&, unsigned int, unsigned char
, unsigned int, bool) at c:\users\david\documents\arduino\hardware\espressif\esp32\tools\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x4014cfea: AsyncWebServerRequest::_handleUploadByte(unsigned char, bool) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 370
0x400d481a: AsyncWebServerRequest::_parseMultipartPostByte(unsigned char, bool) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 402
0x400d5bae: AsyncWebServerRequest::_onData(void*, unsigned int) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 137
0x400d5d79: std::_Function_handler >::_M_invoke(const std::_Any_data &, , , , ) at C:\Users\David\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebRequest.cpp line 75
0x400d3739: AsyncClient::_recv(tcp_pcb*, pbuf*, signed char) at c:\users\david\documents\arduino\hardware\espressif\esp32\tools\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x400d3782: AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, signed char) at C:\Users\David\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 977
0x400d3a22: _async_service_task(void*) at C:\Users\David\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 148
0x4008ba0d: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 141
NOTE:
I found. And problem solved by SPIFFS.format().

But where did you put the SPIFFS.format() ?
I tried it but it seems to crash anyway.

Here,
https://github.com/davidgevorgian/ESP8266UpdatePack/tree/master/ESP32

@spyder0069
Copy link

Thanks, that's an interesting idea! I will check and report back. Maybe it's SPIFFS who corrupts the heap, and web server is just poor victim.

@me21 did you find a resolution for this error? I am having a similar failure that I am trying to track down. From my main page if I click a link that directs to a new page and I return back and try it again several times I crash and reboot with:

`CORRUPT HEAP: Bad head at 0x3ffb8768. Expected 0xabba1234 got 0x3ffb8940
assertion "head != NULL" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c", line 214, function: multi_heap_free
abort() was called at PC 0x400fd93f on core 0

Backtrace: 0x4008d540:0x3ffbb360 0x4008d771:0x3ffbb380 0x400fd93f:0x3ffbb3a0 0x4008d19d:0x3ffbb3d0 0x400858f2:0x3ffbb3f0 0x40086f1d:0x3ffbb410 0x4000bec7:0x3ffbb430 0x40136503:0x3ffbb450 0x40136563:0x3ffbb470 0x401365ab:0x3ffbb490 0x40138cca:0x3ffbb4b0 0x40138d32:0x3ffbb4d0 0x400edcd9:0x3ffbb4f0 0x40134edc:0x3ffbb510 0x40089491:0x3ffbb540

Decoding stack results
0x4008d540: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155
0x4008d771: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170
0x400fd93f: __assert_func at ../../../.././newlib/libc/stdlib/assert.c line 63
0x4008d19d: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c line 214
0x400858f2: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c line 268
0x40086f1d: _free_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c line 42
0x40136503: mem_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/lwip/src/core/mem.c line 151
0x40136563: do_memp_free_pool at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/lwip/src/core/memp.c line 432
0x401365ab: memp_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/lwip/src/core/memp.c line 489
0x40138cca: tcp_close_shutdown at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/lwip/src/core/tcp.c line 311
0x40138d32: tcp_close at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/lwip/src/core/tcp.c line 409
0x400edcd9: _tcp_close_api(tcpip_api_call_data*) at C:\arduino\SKETCHBOOK\libraries\AsyncTCP\src\AsyncTCP.cpp line 348
0x40134edc: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/lwip/src/api/tcpip.c line 124
0x40089491: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143`

@spyder0069
Copy link

spyder0069 commented May 17, 2019

It appears my issue may be solved. I'll try my best to explain what was happening. My program had a main page that ran a function using xmlhttprequest to dynamically load data to it on a 1 second loop. This calls another page that gets the info in the background and posts it to the page you are viewing. This main page had links to redirect to other pages. If I would switch to one of these other pages and back several times eventually I would cause the error. What I think was happening was I was hitting the link to redirect at the same time that the function was calling for new data and it was switching to the new page but also I was getting the response from background page and that fouled things up. What seems to have fixed it is creating a flag and if its not set then my function sends the response to the main page with the new data. If any of my redirect pages load up they immediately set the flag so that the response from the background page will not be run.

@stale stale bot removed the stale label Sep 23, 2019
@stale
Copy link

stale bot commented Nov 22, 2019

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 22, 2019
@JohnGENZ
Copy link

I find a similar error. I am working on characterising it better. If I repeatedly load a page with Edge I get a heap corruption - if I do the same thing with Chrome it is robust and does not generate the error.

@stale
Copy link

stale bot commented Nov 29, 2019

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the stale label Nov 29, 2019
@X-WL
Copy link

X-WL commented Nov 29, 2019

up

@JohnGENZ
Copy link

JohnGENZ commented Dec 5, 2019

My issue seems to be a conflict with async requests to an NTP server. Hard to reproduce in a useful way.

@stale
Copy link

stale bot commented Feb 3, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 3, 2020
@sfranzyshen
Copy link

stale bot is not useful ... it degrades development ... please eliminate this feature from this repository ...

@stale
Copy link

stale bot commented Feb 3, 2020

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the stale label Feb 3, 2020
@stale
Copy link

stale bot commented Apr 3, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 3, 2020
@stale
Copy link

stale bot commented Apr 17, 2020

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Apr 17, 2020
@kadaan
Copy link

kadaan commented Apr 7, 2021

This should be reopened

@zekageri
Copy link

zekageri commented Apr 9, 2021

This should be reopened

indeed

@xlyric
Copy link

xlyric commented Apr 12, 2021

same problem :
PORT
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x4000c29b PS : 0x00060630 A0 : 0x800dab25 A1 : 0x3ffd7430
A2 : 0x3ffd9e0d A3 : 0xbaad5678 A4 : 0x000000f5 A5 : 0x3ffd9e0d
A6 : 0x00000000 A7 : 0x3ffb1ec0 A8 : 0x00000000 A9 : 0x3ffd73f0
A10 : 0x3ffd7b3c A11 : 0x3ffd7d47 A12 : 0x3ffd9e13 A13 : 0x3ffd9f02
A14 : 0x3ffd7c58 A15 : 0x000000ef SAR : 0x00000008 EXCCAUSE: 0x0000001c
EXCVADDR: 0xbaad5678 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffe

ELF file SHA256: 0000000000000000

Backtrace: 0x4000c29b:0x3ffd7430 0x400dab22:0x3ffd7440 0x400dad25:0x3ffd74d0 0x4018a6be:0x3ffd7520 0x400d6f11:0x3ffd7540 0x4017590b:0x3ffd7560 0x40175a74:0x3ffd7590 0x401760c5:0x3ffd75b0 0x4008a30e:0x3ffd75e0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8

PC: 0x4000c29b
EXCVADDR: 0xbaad5678

Decoding stack results
0x400dab22: AsyncAbstractResponse::_fillBufferAndProcessTemplates(unsigned char*, unsigned int) at .pio\libdeps\esp32dev\ESP Async WebServer\src\WebResponses.cpp line 455
0x400dad25: AsyncAbstractResponse::_ack(AsyncWebServerRequest*, unsigned int, unsigned int) at .pio\libdeps\esp32dev\ESP Async WebServer\src\WebResponses.cpp line 313
0x4018a6be: AsyncWebServerRequest::_onAck(unsigned int, unsigned int) at .pio\libdeps\esp32dev\ESP Async WebServer\src\WebRequest.cpp line 201
0x400d6f11: std::_Function_handler >::_M_invoke(const std::_Any_data &, , , , ) at .pio\libdeps\esp32dev\ESP Async WebServer\src\WebRequest.cpp line 73
0x4017590b: AsyncClient::_sent(tcp_pcb*, unsigned short) at c:\users\c_lyr.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271
0x40175a74: AsyncClient::_s_sent(void*, tcp_pcb*, unsigned short) at .pio\libdeps\esp32dev\AsyncTCP\src\AsyncTCP.cpp line 1203
0x401760c5: _async_service_task(void*) at .pio\libdeps\esp32dev\AsyncTCP\src\AsyncTCP.cpp line 165
0x4008a30e: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

@kalifsoup
Copy link

kalifsoup commented Apr 24, 2021

Hi there,

Same here. Not found final solution but... Chrome update (v54) and Firefox removes the ability to make synchronous XMLHttpRequest calls.

@atanisoft
Copy link
Contributor

@kalifsoup You can still do synchronous http calls but you need to approach it differently...

// array to hold all async request calls
var reqs = [];
// add a call to load /wifi
reqs.push(async () => {
  const response = await fetch('/wifi');
  var json = await response.json();
  $('#wifi-mode').val(json.mode);
  $('#wifi-sta-ssid').val(json.ssid);
});
// add a call to load /info
reqs.push(async () => {
  const response = await fetch('/info');
  var json = await response.json();
  $('#node_id').val(pad_hex(json.node_id, 12));
  $('#sw_version').text(json.snip_sw);
  $('[id^=navtab-]').each(function (i, e) {
    $(e).attr('href', '#');
  });
  $('#loading').hide();
  $('#node_info').show();
});
// sequentially send all requests, each request will wait for the previous
// to complete before sending and processing it's response.
reqs.reduce(async (prev, cur) => { await prev; return cur(); }, Promise.resolve(null));

This approach will allow at most one request to be sent at a time, a similar approach can be used to background load various content on demand.

@LK-Simon
Copy link

LK-Simon commented Feb 4, 2024

I know I'm pulling this thread up from the grave, but I've been trying to resolve similar issues of my own, and have come up with a novel solutions.

Ultimately, I was unable to resolve seemingly-random heap corruption issues inside of the async callback... so I gave up trying.

Instead, I changed my approach entirely, and now only use the async callback to place the request data from the client into a custom queue, which is processed by my own thread. This gave me extremely reliable performance, and more flexibility with how I handle async requests from the client via a Web Socket.

Anyway, this does lead me to suspect the likely cause of the issue: the async task's heap size is insufficient!

I believe that the heap allocated to the async task is simply too low for what a lot of us are doing inside that callback (especially when we're parsing string data, or serialising to and from JSON).

Reason I suspect this? Well, if I set too low a heap size on my own threads, I get the same behaviour. Increase the heap size, all is good.

You can actually test this in your own callbacks by calling: uxTaskGetStackHighWaterMark inside the callback and printing its value out to the Serial monitor.

Now, I'll be releasing a library shortly that sits on top of this one, and provides the queuing and queue handling behaviour. I'll come back and share the link once it's ready for human consumption (I have to first fully-separate my own solution from my program and prepare it as a separate library).

Hope it helps :)

@trycoon
Copy link

trycoon commented Feb 5, 2024

@LK-Simon Sounds great! Thanks for taking your time to investigate and releasing a solution! ❤️

@zekageri
Copy link

zekageri commented Feb 5, 2024

I don't want to be a jackass but there is already a stable library with almost the exact same syntax as this one but without all the Async TCP. It is written on top of the esp idf and it is stable AF. Its called PsychicHTTP. Iam using this one so far and no crash at all. It has everything that AsyncTCP has and more.

https://github.com/hoeken/PsychicHttp

@Pablo2048
Copy link

Well, it is, but for those of us, which are using ESP32 and also ESP8266 and want to write firmware for both SOCs is PsychicHttp with no support for ESP8266 unfortunately useless so far IMHO.

@zekageri
Copy link

zekageri commented Feb 5, 2024

Well, it is, but for those of us, which are using ESP32 and also ESP8266 and want to write firmware for both SOCs is PsychicHttp with no support for ESP8266 unfortunately useless so far IMHO.

This is true. It does not support 8266 for now. If more ppl would contribute it could get there

@LK-Simon
Copy link

LK-Simon commented Feb 5, 2024

I just want to reiterate a point here:

We should NOT be processing requests INSIDE the callback!

The reasons:

  • The Heap allocation for the Async Callback Task ("Thread") is simply too small for any meaningful heap allocation (e.g. String parsing and/or JSON Serialization/Deserialization)
  • The Governor expects the callback to return promptly, and if it doesn't, it will "panic"

And there's a third consideration specifically with ESPAsyncWebServer's Web Sockets...

  • Messages from the Client may not be sent in one packet!

We're supposed to use the Callback to ensure that a message is complete, then pass the message (unprocessed) off to our own processing queue to be handled by either the idle task (Thread) or our own (separate and appropriately-allocated) task (Thread).

Side note: I'm saying "task (Thread)" because, in this context, they are used analogously.

I'm packaging up my complete solution for this into a library others can consume (light-weight and dev-friendly)... but the processing part can be applied to literally anything! It's basically an "Event Engine" (same as I've written for Pascal/Delphi, Windows/Mac/Linux C/C++, ObjectiveC, Swift, Python, Lua, and even Java in a former life)... and the inbound messages from clients on the Socket get handed off to the Event Dispatcher, which then (on its own Thread) hands them off to the appropriate "Event Listeners" (which can either be a simple Callback on the Idle Thread, or separate Threads descending from my "Event Thread" type).

Ultimately, this means we return from the Web Socket Callback Method very (very) quickly, and the Heap requirements don't exceed the max heap allocation for that task (Thread) because we don't copy or allocate any strings on the Heap (which is the most common cause of the problems you've all reported in this Issue)

As for this PsychicHttp library, I'll take a look... I'm always happy to help flesh out compatibility to other hardware where I can :)

@LK-Simon
Copy link

LK-Simon commented Feb 5, 2024

I want to add one more observation: if the Client sends a String that meets the maximum packet size of the ESPAsyncWebServer library's Web Socket classes, even attempting to write that String out to the Serial Monitor will actually exceed the maximum allocated heap for the Callback's executing task (Thread).

This is actually a bug in this library that needs to be resolved. The allocation available for the Heap should definitely not be lower than the defacto required allocation for the maximum permitted packet size being sent from the client!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests