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

misleading error message when using ADNS without internet connection #1062

Closed
jsaak opened this issue Dec 1, 2018 · 1 comment
Closed

misleading error message when using ADNS without internet connection #1062

jsaak opened this issue Dec 1, 2018 · 1 comment
Labels
Component: mosquitto-broker Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Milestone

Comments

@jsaak
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 (1.1.1.1:188)
1543645727: net__try_connect_step1
1543645727: Connecting bridge (step 2) olivia (1.1.1.1:188)
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
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
@ralight
Copy link
Contributor

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 added the Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. label Dec 4, 2018
@ralight ralight closed this as completed Dec 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: mosquitto-broker Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants