(RTOS_SDK) mbedtls_ssl_write low memory issue

Posts: 13
Joined: Tue Feb 07, 2017 1:49 pm

(RTOS_SDK) mbedtls_ssl_write low memory issue

Postby gustavomassa » Wed Jul 05, 2017 11:45 am


The function mbedtls_ssl_write get stuck forever when there is low heap memory, about 3-4kb of heap. The ssl_write will block forever until you reset the device, it only occurs when the heap memory is low. The interrupts still works while the write is blocking forever. Please investigate.

File -> RTOS_SDK\third_party\mbedtls\library\ssl_tls.c
Function -> int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len )

Digging a little bit more on the issue, I've added vPortEnterCritical() and vPortExitCritical between the "ssl_write" call, then the code always crashes and prints ShowCritical:1 message on the uart.

User avatar
Posts: 386
Joined: Wed Jun 29, 2016 7:17 pm
Location: India

Re: (RTOS_SDK) mbedtls_ssl_write low memory issue

Postby pratik » Thu Jul 06, 2017 12:41 pm

So this is an RTOS SDK issue I guess? Because mbedTLS on nonOS SDK works fine near minimum heap usage limits too, as long as it can allocate memory for operations. And if it cannot, a memory allocation error is generated (and sending fails).
Which version of SDK are you using? Can you attach a log?
I would like to know if this failure occurs during a callback or just before a callback.

For temporarily fixing this, try to check free heap before calling the function that causes failure with low heap space.
Pratik Panda
Website: http://www.PratikPanda.com

Custom firmware, Knowledge base and freelancing (ESP8266/ESP32):

Her Majesty
Posts: 125
Joined: Mon Oct 27, 2014 11:09 am

Re: (RTOS_SDK) mbedtls_ssl_write low memory issue

Postby Her Majesty » Thu Jul 06, 2017 2:38 pm

Without enough memory, you can do nothing.
Which version of ESP8266 RTOS SDK are you using? Maybe you can try the latest one.

Posts: 14
Joined: Thu May 04, 2017 12:53 am

Re: (RTOS_SDK) mbedtls_ssl_write low memory issue

Postby ememberus » Sat Jul 15, 2017 2:36 am

Without enough memory, you can do nothing.

Running an infinite loop and waiting gives developers no clue to what is wrong and how to resolve the issue.
In case of low memory, you can return an error code or message indicating this explicitly.
Silent default behavior will poison everything and should be completely eliminated.

Who is online

Users browsing this forum: No registered users and 1 guest