-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calloc fails even with very large memory block available (IDFGH-10391) #11647
Comments
It (might) be a misconfiguration (I'm not sure), but here's the issue: |
Please check the memory allocation configuration for mbedTLS stack as per below reference: esp-idf/components/mbedtls/port/include/mbedtls/esp_config.h Lines 100 to 128 in 2135042
Additionally, putting some debug prints in |
I've found the root cause, which is caused by LwIP overriding mbedtls calloc/free functions here: User calls: to: And wherein LwIP wrongly identify the MBEDTLS config with this preprocessor: In which its calloc function compares with a fixed preprocessor value of 1600 if not overriden: |
How were you able to resolve this issue? I'm having issues myself where the dynamic buffer for mbedTLS isn't freeing itself after reading packets greater than 2900 bytes. |
You can increase MEM_SIZE of LwIP configuration to a good number (I've did try for 95000) if you don't want to take a greater risk by using my own patch of esp-lwip. However I've made a good progress and have good tests of it. Except this issue. I'm happy to guide you further if you wanted. |
Thanks! Where had you found |
You can find it in lwip/opt.h
…On Sat, Jul 8, 2023, 12:16 bmkuter ***@***.***> wrote:
Thanks! Where had you found MEM_SIZE?
—
Reply to this email directly, view it on GitHub
<#11647 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH3O7J3ZTTTHP25GQYYPRM3XPEQOXANCNFSM6AAAAAAZCLXCAQ>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Answers checklist.
IDF version.
v4.4
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32DevKit1
Power Supply used.
USB
What is the expected behavior?
Hi there,
I'm maintaining an Arduino-based H4AsyncTCP library, developing TLS over LwIP TCP by utilizing ALTCP, I've setup everything (Certificates, altcp_tls_config(s)), but the altcp_tls_new() call ended up failing to return a pcb.
After further debugging, I've found that a calloc has failed to allocate memory at:
https://github.com/espressif/mbedtls/blob/15b55d406db3918bac88aaf5ef2c6e036d1e0f0e/library/ssl_tls.c#L3857
Wherein I've diagnosed
heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT)
andheap_caps_get_largest_free_block(MALLOC_CAP_8BIT)
(which gave me the same value).Debug Output:
For a MQTT client _connect():
Note that H: Free Heap, M: Largest block (default), B: Largest block (8bit), S: StackHighWaterMark.
A similar output resulted by a server initiating.
I'm using a customized build of Arduino libraries, activating
LWIP_ALTCP
,LWIP_ALTCP_TLS
, andLWIP_ALTCP_TLS_MBEDTLS
macros, Plaase refer to this Feature request for more information.What is the actual behavior?
Instead of allocating memory (even if it's available in large volume), it fails.
Steps to reproduce.
I can setup a whole test environment of the project run if really needed, which simplifies the test and installs everything on the fly with switchable TCP/TLS by a macro set. It runs very solid in TCP mode, over PlatformIO.
The text was updated successfully, but these errors were encountered: