New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeout for TCP connect (IDFGH-1541) #3791
Conversation
With this config (where 192.168.0.123 is unreachable):
On esp_http_client_perform() without changes: (~18 seconds to return)
With changes: (~1000ms to return)
|
Thank you @boarchuz for sharing this useful udpate. My concern is however the compatibility of existing applications that use esp_transport indirectly (e.g. via esp_http_client), where the only timeout configured is used for both connection and read/write operations. Thinking that the default value of 1000ms is |
Hi David, I think that would be best addressed in a separate PR/issue though, especially since, as of 3.2.2 release, esp_http_client has a lot of other timing issues too. Namely that it is ignoring all other timeouts anyway (if a poll times out, it will keep retrying until the ~18 second socket timeout rather than immediately returning an error). There have been a lot of updates recently so I'll have to test it in its current state before raising those issues. The 1000ms was an example, set in the config in the snippet above. It's not the default value. esp_http_client has a default 5000ms timeout. I guess this PR is seeking to clarify whether tcp_connect should do what it says on the tin or if we're advised to fiddle with LWIP_TCP_SYNMAXRTX instead and leave this layer alone. |
Thanks for contribution, please help refer to 0c7204e. Thanks. |
Currently, the timeout_ms parameter is actually used for the SO_RCVTIMEO option rather than for the socket connection. Therefore, regardless of the timeout_ms value, connect() will block for a long time (~20 seconds) if a connection cannot be established (eg. the server is offline). This is very inefficient, especially in the common case of battery-powered devices connecting to a local server, where <100ms might be enough to determine if the server is online.
Efficiency aside, I think it's far more intuitive for a 'timeout_ms' parameter of 'tcp_connect' to actually be the connection timeout.
With this, tcp_connect will return an error if the socket is not write-able before timeout_ms expires. I've tested via esp_http_client.