Page 1 of 1

HTTPS cancel download of large file

Posted: Fri Feb 24, 2023 4:55 pm
by jakobj
We are downloading a large file using HTTPS and calling "esp_http_client_perform()" in blocked mode.

Our App requires possibility for canceling the download, we have implemented a function that calls: esp_http_client_close(client)
The call is made from another task than the download task.

This works most of the times, but sometimes we see an error, the backtrace is below.

What is correct procedure to cancel a download ?

0x40155cf7: ssl_get_next_record at C:/Espressif/frameworks/esp-idf-v5.0/components/mbedtls/mbedtls/library/ssl_msg.c:4617

0x40155d82: mbedtls_ssl_read_record at C:/Espressif/frameworks/esp-idf-v5.0/components/mbedtls/mbedtls/library/ssl_msg.c:3869

0x40155eb2: mbedtls_ssl_read at C:/Espressif/frameworks/esp-idf-v5.0/components/mbedtls/mbedtls/library/ssl_msg.c:5467

0x40151141: esp_mbedtls_read at C:/Espressif/frameworks/esp-idf-v5.0/components/esp-tls/esp_tls_mbedtls.c:222

0x401afb9e: esp_tls_conn_read at C:/Espressif/frameworks/esp-idf-v5.0/components/esp-tls/esp_tls.c:98

0x40194310: ssl_read at C:/Espressif/frameworks/esp-idf-v5.0/components/tcp_transport/transport_ssl.c:253

0x401b1829: esp_transport_read at C:/Espressif/frameworks/esp-idf-v5.0/components/tcp_transport/transport.c:140

0x40151d01: esp_http_client_get_data at C:/Espressif/frameworks/esp-idf-v5.0/components/esp_http_client/esp_http_client.c:1011

0x401531eb: esp_http_client_perform at C:/Espressif/frameworks/esp-idf-v5.0/components/esp_http_client/esp_http_client.c:1188
.......

Re: HTTPS cancel download of large file

Posted: Sat Feb 25, 2023 2:14 am
by ESP_Sprite
Smells like something is not properly re-entrant, which causes the spurious errors. Is there a way to handle the cancel in the download task, as in, the cancelling task raises a semaphore, the download task checks that and calls esp_http_client_close() function?

Re: HTTPS cancel download of large file

Posted: Sat Feb 25, 2023 8:24 am
by jakobj
Yes, I thing that maybe could be the reason.
I have tried to run the http client in async mode, but without luck.
Have created another forum question on this problem.