Request: Connection Timeout Parameter
Hi,
Have there been any plans to add a connection timeout parameter to the method net__socket_connect()?
Without a timeout the connect may take very long in case the target-address is wrongly configured, e.g. when it's pointing to a firewalled host/port.
The solution I came up with so far is Linux specific, so it's not a candidate for a PR.
Best regards, Matthias
I have encountered the same problem. When connecting to a target address, which is not in the current network subnet, the socket connect timeout of the OS comes into play. In my case, Raspbian OS, the timeout is 60 seconds.
A runtime configurable timeout would be a great solution.
Best Regards
Erwin
This is my big problem right now, it took my application out of service for a very long time. Any way for working around this problem? I am working on Linux environment.
Thanks, Cong Nga Le
Hi @congngale ,
To solve this for us I decided to patch libmosquitto in the file net_mosq.c. I added the following lines in the method net__try_connect()
// SetTimeout (Linux-specific). See RFC 6298, Section 5.5
// Send a total of 4 SYN packets => Timeout ~= 2⁰+2¹+2²+2³ = 15sec
int synRetries = 3;
setsockopt(*sock, IPPROTO_TCP, TCP_SYNCNT, &synRetries, sizeof(synRetries));
rc = connect(*sock, rp->ai_addr, rp->ai_addrlen);
This sets an option on the socket to limit the number of SYN-retries. It's not portable and also not configurable but works for us. Maybe it's an option for you as well.
Regards, Matthias