-
Notifications
You must be signed in to change notification settings - Fork 45
Google IoT client's memory limiter conflicts with ESP-IDF heap corruption detector (CA-102) #18
Comments
Hi @DaStoned, Thank you for reporting the issue and the detailed analysis. Can you please provide your sdkconfig if possible? |
Hi @supreetd21, I was able to reproduce the problem in 60-80 percent of cases when doing this:
I only observed the problem when starting them in parallel. When starting the HTTPS download later (after IoT Core connection was made), there were no problems. The issue triggered specifically when HTTPS completed. It seems to me that HTTPS download failing (e.g through timeout) or completing was the cause, as this shut down the TLS connection to HTTPS server and produced the assert. My sdkconfig.txt. I switched to CONFIG_HEAP_POISONING_COMPREHENSIVE when encountering problems. The HTTPS client and Google IoT Core together manage to consume a lot of heap, but the "high water mark" of heap consumption always shows over 60 KiB remaining when the issue is not triggered (i.e. all tasks complete successfully). Also the "high water mark" of stacks for all involved tasks have at least 1 KiB remaining. So I don't think I ran into an actual memory depletion problem. I can produce more detailed log output, if needed. |
Hi, @DaStoned, I could reproduce the issue even when heap poisoning was disabled. On further inspection, I noticed the root cause, very similar to your hypothesis: Background:
Issue:
Without memory limiter, the replaced functions act same as vanilla memory allocations. (
Note:
|
Thank you for the explanation. I'm fortunate to not require the memory limiter functionality (or so I believe), so I can just ignore it. Otherwise it would be quite tricky to avoid such race conditions reliably in application code. Effectively, TLS operations become a mutually exclusive resource :) I'd have to stop all other TLS tasks while iotc library does connect or re-connect, or something to this tune. |
Hi, @DaStoned |
I suppose so: GoogleCloudPlatform/iot-device-sdk-embedded-c#115 |
Hi!
I'm using the excellent Google IoT Core client port from https://github.com/espressif/esp-google-iot. The CMakeLists.txt in this project enables the memory limiter (-DIOTC_MEMORY_LIMITER_ENABLED).
This option seems to conflict rather badly with ESP-IDF v 4.1 heap corruption detection (enabled by HEAP_POISONING_LIGHT or HEAP_POISONING_COMPREHENSIVE). When both the limiter and detector are enabled at the same time (as is the default), then under some circumstances freeing allocated heap memory triggers ESP-IDF heap corruption detector (which reboots the system).
I see that when memory is free()-d by the mbedtls library (e.g. when a TLS session dies due to an error) it fails with this message:
My hypothesis is that multi_heap_free() (on multi_heap_poisoning.c:266) receives a pointer to a "heap poison" header structure generated by iotc_memory_limiter.c instead of its own poison. Since IOTC's header doesn't start with the magic 0xabba1234, it declares heap corrupt.
I would speculate that maybe the sequence of two free()-s would have to be carried out in reverse to the sequence of malloc()-s.
Testing indicates that disabling IOTC's memory limiter fixes the problem. I humbly suggest disabling it by default in https://github.com/espressif/esp-google-iot
The text was updated successfully, but these errors were encountered: