# ESP32 async web server crashes or reboots: heap, big pages and callbacks

> Fix ESP32 web server resets: serve big pages from flash storage, avoid long callbacks, build less text in memory and watch the free heap.

Canonical: https://roboticsengineering.in/fix/esp32-async-web-server-crashes-ram-heap/ | Published: 2026-11-03 | Updated: 2026-11-04

**Serve large pages from the file system and keep callbacks short.** Building big strings in RAM exhausts the heap.

## What the message means

Each request takes memory. Large strings and slow code inside a callback block the network task and can cause a watchdog reset.

## Fix it in this order

1. Print the free heap now and then to see if it falls over time.
2. Store the web page in flash and send it as a file.
3. Do not call delay() or long loops inside request callbacks.
4. Set a flag in the callback and do the work in loop().
5. Limit the number of clients at once.
6. Read the backtrace after a crash to find the cause.

## Why it happens

An async server runs your request handlers inside its network task. The library’s documentation warns that you cannot delay or yield while waiting for more data in a response callback, and a user report shows a busy-wait inside a handler resetting the board after a few seconds.

Memory is the other cause. Reading a whole file into a String and editing it needs about twice the file size in memory at once, and a large String needs a large block of heap. Sending the page from the file system, or streaming it, avoids that. No exact threshold is documented, so watch free heap over time on your own board.

## If you see this, do this

| You see | Do this |
| --- | --- |
| Crashes on page load | Page built in RAM. |
| Crashes after hours | Memory leak. Watch the heap. |

## Related

[task watchdog](https://roboticsengineering.in/fix/esp32-task-watchdog-got-triggered/), [file system mount failed](https://roboticsengineering.in/fix/esp32-spiffs-littlefs-mount-failed/).

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

## Why this happens

An asynchronous web server handles all requests inside one network task. Your handler code runs in that task, so any delay or loop inside a handler holds up every other connection and the watchdog can reset the board. The library’s guidance is to keep handlers short and move slow work out of them.

Memory is the other limit. Each connection needs buffers, and a page built as one large String needs a single contiguous block of heap. Building the page again and again fragments the heap, so the free memory can look fine in total but still fail to give a big block.

## How to confirm the cause

- Print ESP.getFreeHeap() and ESP.getMaxAllocHeap() every few seconds while you load the page. A steady fall in free heap points to a leak.
- A large gap between the free heap and the largest allocatable block points to fragmentation from big Strings.
- Read the backtrace printed after a reset. A watchdog message means a handler or task blocked.
- Comment out handlers one by one and see which request causes the crash.
- Load the page from several tabs at once to see if more clients make it worse.

## Worked example

Serve the page from the file system, and leave slow work to loop() with a flag. The handler only sets the flag and replies at once.

```
AsyncWebServer server(80);
volatile bool doWork = false;

void setup() {
  LittleFS.begin(true);
  server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
  server.on("/go", HTTP_GET, [](AsyncWebServerRequest *r) {
    doWork = true;
    r->send(200, "text/plain", "ok");
  });
  server.begin();
}
void loop() {
  if (doWork) { doWork = false; /* slow task here */ }
}
```

## Common mistakes

- Calling delay() or a long loop inside a request handler.
- Building the whole page in a String on every request.
- Touching hardware or shared variables in a handler without thinking about the other task.
- Never checking free memory until the first crash.

## If this did not fix it

- The power supply, since Wi-Fi bursts can reset a board on a weak USB port.
- A stack overflow in another task, which also gives a reboot.
- The file system: a failed mount makes serveStatic return errors.
