- Notifications
You must be signed in to change notification settings - Fork 6
Having problemen with AsyncHTTPS memory leak #11
Description
Describe the bug
When utilizing the AsyncHTTPS library there is a decrease of the available heap space with about 100 to about 200 bytes per https request until it runs out of heap space and crashes.
Steps to Reproduce
I modified the included example slightly to demonstrate the problem;
https://github.com/khoih-prog/AsyncHTTPSRequest_Generic/blob/main/examples/AsyncHTTPSRequest_ESP/AsyncHTTPSRequest_ESP.ino - Add a global variable;
uint previousHeapSize = ESP.getFreeHeap();
- Modified void sendRequest() function;
void sendRequest() { static bool requestOpenResult; ///***Add this uint heapSize = ESP.getFreeHeap(); Serial.print("Current HeapFree: "); Serial.print(heapSize); if(previousHeapSize > heapSize ) { Serial.print(" decrease: "); Serial.println(previousHeapSize - heapSize); }else{ Serial.print(" increase: "); Serial.println(heapSize - previousHeapSize); } previousHeapSize = heapSize; ///***End Add this if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - Commented out the Serial.print within requestCB to prevent printing of output
if (readyState == readyStateDone) { /*Serial.println(F("\n**************************************")); Serial.println(request->responseText()); Serial.println(F("**************************************"));*/ request->setDebug(false); } -
Commented out the ticker1.attach within setup()
//ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); -
Decreased the HTTPS_REQUEST_INTERVAL to 10 seconds to faster show the problem, although it also happens when you leave the interval to the example's default
// 300s = 5 minutes to not flooding #define HTTPS_REQUEST_INTERVAL 10 //300 Expected behavior
Expected for the free heap size to be remain stable after initial initialization with minor variations both in increase and decrease of available free heap space.
Actual behavior
The modified demo shows an ongoing decrease of available heap space:
11:05:07.402 -> Starting AsyncHTTPSRequest_ESP using ESP32_DEV 11:05:07.402 -> AsyncTCP_SSL v1.2.0 11:05:07.448 -> AsyncHTTPSRequest_Generic v2.0.1 11:05:07.529 -> Connecting to WiFi SSID: Wireless 11:05:08.036 -> ..... 11:05:10.006 -> AsyncHTTPSRequest @ IP : 172.16.16.241 11:05:10.053 -> Current HeapFree: 264648 increase: 102796 11:05:20.034 -> Current HeapFree: 199900 decrease: 64748 11:05:30.020 -> Current HeapFree: 199548 decrease: 352 11:05:40.037 -> Current HeapFree: 199376 decrease: 172 11:05:50.048 -> Current HeapFree: 199248 decrease: 128 11:06:00.037 -> Current HeapFree: 199060 decrease: 188 11:06:10.022 -> Current HeapFree: 198892 decrease: 168 11:06:20.021 -> Current HeapFree: 198764 decrease: 128 11:06:30.003 -> Current HeapFree: 198592 decrease: 172 11:06:40.039 -> Current HeapFree: 198408 decrease: 184 11:06:50.032 -> Current HeapFree: 198084 decrease: 324 11:07:00.034 -> Current HeapFree: 197932 decrease: 152 11:07:10.009 -> Current HeapFree: 197760 decrease: 172 11:07:20.017 -> Current HeapFree: 197604 decrease: 156 11:07:30.048 -> Current HeapFree: 197428 decrease: 176 11:07:40.021 -> Current HeapFree: 197272 decrease: 156 11:07:50.020 -> Current HeapFree: 197080 decrease: 192 11:08:00.015 -> Current HeapFree: 196956 decrease: 124 11:08:10.047 -> Current HeapFree: 196788 decrease: 168 11:08:20.016 -> Current HeapFree: 196612 decrease: 176 11:08:30.029 -> Current HeapFree: 196460 decrease: 152 11:08:40.022 -> Current HeapFree: 196300 decrease: 160 11:08:50.037 -> Current HeapFree: 196132 decrease: 168 11:09:00.032 -> Current HeapFree: 196016 decrease: 116 11:09:10.025 -> Current HeapFree: 195824 decrease: 192 11:09:20.011 -> Current HeapFree: 195656 decrease: 168 11:09:30.003 -> Current HeapFree: 195512 decrease: 144 11:09:40.040 -> Current HeapFree: 195320 decrease: 192 11:09:50.007 -> Current HeapFree: 195168 decrease: 152 11:10:00.013 -> Current HeapFree: 195008 decrease: 160 11:10:10.015 -> Current HeapFree: 194892 decrease: 116 11:10:20.002 -> Current HeapFree: 194700 decrease: 192 11:10:30.032 -> Current HeapFree: 194556 decrease: 144 11:10:40.003 -> Current HeapFree: 194380 decrease: 176 11:10:50.002 -> Current HeapFree: 194228 decrease: 152 11:11:00.011 -> Current HeapFree: 194056 decrease: 172 11:11:10.017 -> Current HeapFree: 193916 decrease: 140 11:11:20.025 -> Current HeapFree: 193744 decrease: 172 11:11:30.005 -> Current HeapFree: 193572 decrease: 172 11:11:40.001 -> Current HeapFree: 193424 decrease: 148 11:11:50.007 -> Current HeapFree: 193244 decrease: 180 11:12:00.002 -> Current HeapFree: 193108 decrease: 136 11:12:10.003 -> Current HeapFree: 192928 decrease: 180 11:12:20.018 -> Current HeapFree: 192796 decrease: 132 11:12:30.035 -> Current HeapFree: 192608 decrease: 188 11:12:40.003 -> Current HeapFree: 192452 decrease: 156 11:12:50.010 -> Current HeapFree: 192296 decrease: 156 Debug and AT-command log (if applicable)
N/A
Screenshots
N/A
Information
- Arduino IDE version 1.8.16)
- ESP32 Wrover device using Board manager: ESP32 v3.02
- OS Windows 11