You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In current repository, tcp_connect in esp_transport has this signature:
static int tcp_connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms)
Yet, inside the function, there are 2 blocking functions being called and none will respect the timeout_ms given.
The first one is inet_pton/resolve_dns and the second one is connect.
Please notice that lwip does not respect the socket option SO_SNDTIMEO for connect.
As a result, if a server takes forever to connect (for example, by being down), tcp_connect will block indefinitively.
The correct way to have a timeout here is to set the socket as non blocking (via fcntl), call connect, then select for socket writeability within the given timeout.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
tcp_connect does not respect the timeout parameter
tcp_connect does not respect the timeout parameter (IDFGH-2971)
Mar 26, 2020
Also, as a more general remark, the parameter timeout_ms in all those transport functions should be called inactivity_time_ms instead since the timeout option set on a socket is reset on socket activity. So if you're receiving a byte per second with a timeout_ms set to 2s, and you are receiving 5 bytes, it'll actually take 5 seconds to complete.
We've noticed that TCP sockets seem to block if, for example, an unreachable numeric IPv4 address is supplied. Sounds like this may be the underlying issue.
You've resolved one issue but not the other. resolve_dns is still blocking.
To resolve a DNS name asynchronously, you should use LWIP's dns_gethostbyname and a semaphore.
In current repository,
tcp_connect
in esp_transport has this signature:Yet, inside the function, there are 2 blocking functions being called and none will respect the
timeout_ms
given.The first one is
inet_pton
/resolve_dns
and the second one isconnect
.Please notice that lwip does not respect the socket option
SO_SNDTIMEO
for connect.As a result, if a server takes forever to connect (for example, by being down),
tcp_connect
will block indefinitively.The correct way to have a timeout here is to set the socket as non blocking (via
fcntl
), callconnect
, thenselect
for socket writeability within the given timeout.The text was updated successfully, but these errors were encountered: