Open hemeleerse opened 11 months ago
You have a String object that is disappearing before you can use it. Don't pass objects between functions, that's what pointers are for. Treat anything out of your local context as a constant (or put mutexes on them). Finish your handler routines quickly.
Looks like a variable has gone out of scope or a pointer no longer refers to valid memory. If you are doing async data processing, you may need to malloc memory for storage and free the memory once you are done. I have to do that on certain messages when they are qued and processed on a different thread.
Is it possible your ESP receives a connection request from some client, tries to allocate some memory to handle it and then the client no longer replies or the network connection of the ESP gets disconnected?
Other use cases where you end up with crashes in the String destructor is when you either memcpy a String object (which you shouldn't do for ovbious reasons) or construction failed of the String object.
Typically this last one may occur when using emplace_back
on std:: containers which hold objects with a String
member.
I can also imagine strange things may happen with classes/structs using inheritance and calling member functions which do stuff on String
objects from their constructor/destructor.
I have the same issue using the Arduino IDE 2
This issue seems to be related to Wifi usage and the AsyncTCP library. I'm not sure where it happens or what is causing it but it appears as if there's a memory leak filling up the HEAP. My gut feeling says this has to do with TCP connections that remain open.
2k memory chunks are reserved from the heap until some unclear threshold or a watchdog detecting corrupt memory.
I'm working on an ESP32 C3 with WiFi.h, WiFiUdp.h, ArduinoOTA.h, Adafruit_NeoPixel.h, ESPmDNS.h, AsyncTCP.h, ESPAsyncWebSrv.h
Below sketch has continuous decreasing HEAP, multiple TCP connections seem to have a "stimulating" effect on the eventual watchdog restart.
Same issue with WiFi and AsyncTCP lib. Can't isolate it yet, sporadically happens....
Can you try to make a number of calls (e.g. frequent refreshing of a webpage) to decrease available free memory, then leave it alone and just periodically print the free memory on the serial port.
I think you will see this memory be freed after ~ 2 minutes. If this is what is happening, then it probably has nothing to do with AsyncTCP.
I had the same problem but with WiFi from Arduino. I could only instance the WiFiClient once so I passed it through a function parameter for other classes to use and that created a copy of the WiFiClient. The problem is that WiFiClient uses async functions and the copy of WiFiClient got in the way of the other WiFiClient. I then passed the WiFiClient as an adress with & and not as a copy and then everything worked.
Board
M5Stack-Core2
Device Description
Nothing connected
Hardware Configuration
Nothing connected
Version
latest master (checkout manually)
IDE Name
PlatformIO
Operating System
Windows10
Flash frequency
240
PSRAM enabled
yes
Upload speed
115200
Description
System restarts in a random way. Can't link the restart to any activity, action, input. Backtrace shows link to the AsyncWebServer I'm running on the device. Any hint on where to start looking is welcome.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide