espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.66k stars 7.29k forks source link

The TCP transport layer is unstable (IDFGH-13361) #14274

Open kanjiviroja1991 opened 3 months ago

kanjiviroja1991 commented 3 months ago

Answers checklist.

IDF version.

v5.2.1

Espressif SoC revision.

ESP32

Operating System used.

Windows

How did you build your project?

Command line with Make

If you are using Windows, please specify command line type.

None

Development Kit.

Custom board

Power Supply used.

USB

What is the expected behavior?

If there is consistent internet service, the websocket connection ought to be reliable and never break. We shouldn't be observe websocket disconnect issue because of tcp driver

What is the actual behavior?

Websocket would regularly disconnect because of a transpot layer issue, even though we were absolutely sure there was no internet connection issue.

Please refer transport layer component from ESP IDF 5.2.1

Steps to reproduce.

  1. Step
  2. Step
  3. Step ...
  4. Connect Internet service (Ethernet, WiFi or GSM)
  5. Connect Websocket and verify connection
  6. Put it in idle state more than 24 hours and capture serial logs
  7. We got this error from below list of API: 29-07-2024 22:08:36,[WS] Error read data 29-07-2024 22:08:36,[WS] Error receive data 29-07-2024 22:20:00,[WS] **** ERR_TCP_TRANSPORT_CONNECTION_FAILED ****

==> rlen = esp_transport_read(client->transport, client->rx_buffer, client->buffer_size, client->config->network_timeout_ms); This API frequently thrown ERR_TCP_TRANSPORT_CONNECTION_FAILED error due to we lost our websocket stability on field.

Debug Logs.

29-07-2024 14:13:39,[WS] ************** ERR_TCP_TRANSPORT_CONNECTION_FAILED **************
29-07-2024 14:13:39,[WS] Error read data
29-07-2024 14:13:39,[WS] Error receive data

More Information.

esp_websocket_client.zip tcp_transport.zip

euripedesrocha commented 4 weeks ago

@kanjiviroja1991 thanks for reporting, could you please provide more details on your setup? If possible to add a reproducer as well. esp_websocket_client version information will be useful also.

From the logs shared, it looks like that there was some instability in the network and the client failed to receive, hence the disconnection.

kanjiviroja1991 commented 4 weeks ago

@euripedesrocha , We checked both wifi and ethernet, and we are also keeping an eye on the connection status on our laptop to see if the network is unstable, so there isn't a problem with the internet. However, we found no problem in network connection but ESP32 somehow detect it network issue.

euripedesrocha commented 4 weeks ago

@kanjiviroja1991 I understand that, but I need to understand your scenario how the network is set and versions in use to try to reproduce. Could you also try with log level set to debug for both websocket client and transport and share the logs?