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

misleading error message when using ADNS without internet connection #1062

jsaak opened this Issue Dec 1, 2018 · 1 comment


None yet
2 participants
Copy link

jsaak commented Dec 1, 2018

When the broker tries to connect to a bridge when there is no internet, then error message is:
"Error creating bridge: Protocol not supported."
instead of
"Network unreachable"

I added some debug code:

1543645727: Connecting bridge (step 1) olivia (
1543645727: net__try_connect_step1
1543645727: Connecting bridge (step 2) olivia (
1543645727: net__try_connect_step2
1543645727: addrinfo: (ai_flags: 40, ai_family: 2, ai_socktype: 1, ai_protocol: 6)
1543645727: addrinfo: (ai_flags: 40, ai_family: 2, ai_socktype: 2, ai_protocol: 17)
1543645727: addrinfo: (ai_flags: 40, ai_family: 2, ai_socktype: 3, ai_protocol: 0)
1543645727: 3Error creating bridge: Protocol not supported.

This means, that when there is no internet, adns gives back 3 addrinfo: 6 == TCP, 17 == UDP and 0 which is invalid.

I think the best solution would be to give SOCK_STREAM to getaddrinfo_a.
We do not want UDP connections at all.
And with the hint, it does not give back protocol 0.

In lib/net_mosq.c:net__try_connect_step1

  struct addrinfo hints;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_socktype = SOCK_STREAM;
  mosq->adns->ar_request = &hints;

The reason this is not a pull request, is that i am not sure that stack allocated addrinfo is a good solution. It may need to be heap allocated.

@ralight ralight added this to the 1.5.5 milestone Dec 4, 2018

ralight added a commit that referenced this issue Dec 4, 2018

When using ADNS, don't ask for all network protocols when connecting.
This can lead to confusing "Protocol not supported" errors if the
network is down, because UDP sockets are provided.

Thanks to jsaak.

Closes #1062.

Bug: #1062

This comment has been minimized.

Copy link

ralight commented Dec 4, 2018

Thanks very much. In my testing it was still unreliable using a stack allocated hints struct, so I've implemented it with the heap. It's in the fixes branch if you would like to give it a test.

@ralight ralight closed this Dec 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment