Skip to content
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

Request: Connection Timeout Parameter #949

Open
matthias1000 opened this issue Sep 4, 2018 · 3 comments
Open

Request: Connection Timeout Parameter #949

matthias1000 opened this issue Sep 4, 2018 · 3 comments
Labels
Component: libmosquitto Type: Enhancement A new feature for a minor or major release.

Comments

@matthias1000
Copy link

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

@helioz2000
Copy link

helioz2000 commented Sep 6, 2018

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

@toast-uz toast-uz added Type: Enhancement A new feature for a minor or major release. Component: libmosquitto labels Sep 10, 2018
@congngale
Copy link

congngale commented Sep 11, 2018

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

@matthias1000
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: libmosquitto Type: Enhancement A new feature for a minor or major release.
Projects
None yet
Development

No branches or pull requests

4 participants