Skip to content

Commit 135c1cc

Browse files
committed
extmod/modtls_mbedtls: Do gc_collect and retry ssl_init on any error.
Contrary to the docs, mbedtls can return more than just MBEDTLS_ERR_SSL_ALLOC_FAILED when `mbedtls_ssl_setup()` fails. At least MBEDTLS_ERR_MD_ALLOC_FAILED was also seen on ESP32_GENERIC, but there could possibly be other error codes. To cover all these codes, just check if `ret` is non-0, and in that case do a `gc_collect()` and retry the init. Signed-off-by: Damien George <[email protected]>
1 parent ab4af2c commit 135c1cc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

extmod/modtls_mbedtls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t
639639

640640
ret = mbedtls_ssl_setup(&o->ssl, &ssl_context->conf);
641641
#if !MICROPY_MBEDTLS_CONFIG_BARE_METAL
642-
if (ret == MBEDTLS_ERR_SSL_ALLOC_FAILED) {
642+
if (ret != 0) {
643643
// If mbedTLS relies on platform libc heap for buffers (i.e. esp32
644644
// port), then run a GC pass and then try again. This is useful because
645645
// it may free a Python object (like an old SSL socket) whose finaliser

0 commit comments

Comments
 (0)