me-no-dev / ESPAsyncWebServer

Async Web Server for ESP8266 and ESP32
3.7k stars 1.21k forks source link

Possible memory leak when handling request coming from WAN vs LAN #1343

Closed horendus closed 1 year ago

horendus commented 1 year ago

I'm currently working on a rather large project that relies quite heavily on the espAsyncWebServer. Its heavily optimized now with excellent performance and stability.

The only issue which I just cant get my head around is if I open up the webserver to the outside world using port forwarding and test it from my iPhone over cellular, within a few HTTP requests the ESP32 is out of memory and I have to server up an Out of Memory message instead of sending the CSS and Javascript files to the browser to prevent a full system reboot.

Over LAN I have no such issue. I can sit here refreshing the browser all day with this occurring.

Here is what I have observed with the memory usage.

After sending the entire site which is around 75KB the remaining ESP.getFreeHeap() is down to say 125kb but as soon as I refresh the page and another transfer is initiated ESP.getFreeHeap() has bounces back to 155kb

Now, if I do the SAME thing but using my WAN address to reach the ESP32 ESP.getFreeHeap() is down to about the same level of 125kb HOWEVER apon logging out and back into the site it has NOT bounces back to 155kb, it instead falls further until it goes bellow 100kb in which can I server up an Out of Memory page to prevent a crash.

The heap slowly recovers after a few minutes.

Does anyone know a fix to this or can take a shot at explaining whats happening here and what I can do about it? Whats different about requests coming from WAN vs LAN?

horendus commented 1 year ago

Never mind, due to some sloppy programming when logging in, the browser was making 2 requests to / which over LAN wasnt causing any real problems but over WAN it was. By fixing the double redirect the problem has gone away.