TLS socket timeout when trying to run http OTA

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

TLS socket timeout when trying to run http OTA

Postby RichPiano » Tue May 25, 2021 4:28 pm

When running my app which is based on the "advanced_https_ota" example, I get the following error when trying to connect to my server (a raspberry pi inside my local network)

Error:

Code: Select all

E (37828) esp-tls: [sock=55] select() timeout
E (37828) esp-tls: Failed to open new connection
E (37828) TRANSPORT_BASE: Failed to open a new connection
E (37828) HTTP_CLIENT: Connection failed, sock < 0
E (37838) esp_https_ota: Failed to open HTTP connection: ESP_ERR_HTTP_CONNECT
E (37838) esp_https_ota: Failed to establish HTTP connection
E (37848) OTA.c: ota begin failed
Interpretation:

Apparently esp-tls is complaining, but I'm wondering since I don't even have https enabled. For the ESP https client I have set "Enable https" to false and at the same time, I have enabled "Allow HTTP for OTA" in the ESP HTTPS OTA component config.

I don't know why the http client is still trying to invoke TLS function, or maybe it just appears to me like this.

Steps I followed to solve this problem:

- Checked free heap size before esp_https_ota_begin(). It amounted to 197144 bytes (I believe this should be enough?)
- Activated verbose wifi debug log but without a difference
- Tried the esp_http_client example which works. However, it uses certificates which I dont.
- Potential connection issues: The MQTT client which is running at the same time is able to connect just fine.

There's a single related topic here which is in chinese, but since I don't speak nor read chinese I have difficulties understanding the context or whether or not the problem has been solved. A rough translate suggests what I have tried, logging free heap size and enabling wifi logs among others, but to no avail.

Any ideas?

Sprite
Espressif staff
Espressif staff
Posts: 10636
Joined: Thu Nov 26, 2015 4:08 am

Re: TLS socket timeout when trying to run http OTA

Postby Sprite » Wed May 26, 2021 1:02 am

Can't really help you with the meat of your problem, but I just want to confirm that ESP-TLS also can be used for unencrypted connections and some of our libraries (http, mqtt, ...) use it as such as it's easier than implementing separate codepaths for tls and non-tls connections.

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: TLS socket timeout when trying to run http OTA

Postby RichPiano » Mon May 31, 2021 9:17 am

Thanks for your answer. The problem indeed doesnt' seem to be with encryption or TLS. I enabled lwip debugging and got the following messages:

Code: Select all

...
ethernet_output: sending packet 0x3ffbb4f0
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
lwip_select: timeout expired
E (18688) esp-tls: [sock=54] select() timeout
lwip_close(54)
tcp_close: closing in State: SYN_SENT
tcp_pcb_purge
tcp_pcb_purge: data left on ->unacked
pbuf_free(0x3ffbb4f0)
pbuf_free: deallocating 0x3ffbb4f0
E (18698) esp-tls: Failed to open new connection
...
Poking around in lwip code it seems to me that lwip select() can't find any socket that is ready for writing. However, this seems strange because the connection is established and MQTT can run on another port. I'm yet to discover the exact cause of this. Any help is appreciated!

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: TLS socket timeout when trying to run http OTA

Postby RichPiano » Wed Jul 07, 2021 9:25 am

I'm still trying to resolve the issue. What I have done so far:
  • Used a different interface on my raspberry pi for connection. E.g. my Raspi has an IF with static IP 192.168.1.4 assigned, but now I'm trying to connect to a different IF 192.168.1.106 which is a wifi-dongle. Doing this the error msg at esp-tls level changes to:

    Code: Select all

    E (16031) esp-tls: [sock=54] delayed connect error: Connection reset by peer
  • Tried the http_request example which works fine. The apache server on my Raspberry Pi responds with a 400 error, but packets are coming through!
  • Used tcpdump on my Raspberry Pi to track incoming packets. I was most interested in the TCP three way handshake, because as the error indicates the ESP is left hanging in a SYN-sent state, which means that there was not even a SYN-ack coming back from my Raspi-Server. tcpdump revealed that this is indeed the case: There are no packets coming through at all using both the above mentioned interfaces! However, the barebone sockets example in http_request DOES work as tcpdump shows.
Conclusion: Still not sure what the cause of this is. I can exclude the following I guess:
  • The connection is fine. No DHCP, subnetmask or gateway problems (as I knew before because MQTT and SNTP is working!).
  • Probably not multithreading problem as the advanced_https_ota example doesn't work in standalone either (produces same error).
My guess and further action:
  • Track differences in socket send between barebone socket example (http_request) and https_ota example (advanced_https_ota).
Any help appreciated!! Thank you!

Sprite
Espressif staff
Espressif staff
Posts: 10636
Joined: Thu Nov 26, 2015 4:08 am

Re: TLS socket timeout when trying to run http OTA

Postby Sprite » Thu Jul 08, 2021 1:28 am

Just to confirm: you already get this with the plain advanced_https_ota example? Also, which esp-idf version exactly do you use?

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: TLS socket timeout when trying to run http OTA

Postby RichPiano » Thu Jul 08, 2021 9:31 am

I've solved the problem I think... I'm so stupid sorry!

Plowing through heaps of lwIP code and reading tons of debugmessages I figured out the ARP-request couldn't ever be resolved... which meant I had to check whether the IP I was using was correct. And it indeed was not. I put 192.198 instead of 192.168. I wonder why I couldn't see it, I have checked that multiple times afaik!

Going back into my shame-shell. Till next time and thank you a lot @ESP_Sprite

Sprite
Espressif staff
Espressif staff
Posts: 10636
Joined: Thu Nov 26, 2015 4:08 am

Re: TLS socket timeout when trying to run http OTA

Postby Sprite » Fri Jul 09, 2021 3:43 am

Hehe, no worries, fat-fingering an IP happens to the best of us.

User avatar
mbratch
Posts: 317
Joined: Fri Jun 11, 2021 1:51 pm

Re: TLS socket timeout when trying to run http OTA

Postby mbratch » Tue Apr 21, 2026 3:19 pm

I'm having exactly the same issue and, in my case, I have indeed entered the correct IP address.
It's a non-secure HTTP connection and it works with a different http server I tried (Apache based). I just setup a default IIS service http server on Windows, and I get this failure.

Code: Select all

E (49098) esp-tls: [sock=20] select() timeout
E (49098) transport_base: Failed to open a new connection: 32774
E (49098) HTTP_CLIENT: Connection failed, sock < 0
E (49113) esp_https_ota: Failed to open HTTP connection: ESP_ERR_HTTP_CONNECT
E (49113) esp_https_ota: Failed to establish HTTP connection
W (49133) httpd_uri: httpd_uri: uri handler execution failed

Who is online

Users browsing this forum: Bytespider, Google [Bot], Semrush [Bot] and 1 guest