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

[Bug] Can't Connect to mqtt broker with IPv6 LLA #1536

Open
shoe-perinet-io opened this issue Dec 26, 2023 · 4 comments
Open

[Bug] Can't Connect to mqtt broker with IPv6 LLA #1536

shoe-perinet-io opened this issue Dec 26, 2023 · 4 comments
Assignees
Labels
bug Something isn't working desktop MQTTX Desktop

Comments

@shoe-perinet-io
Copy link

What did I do

Try to connect the MQTTX client to a local MQTT broker. The MQTT broker is resolved via mDNS. It is resolved to an IPv6 LLA, link local address.
server name: mqtt-perimica-hw3kg.local
server IP address: fe80::a:ed8a:9f66:8007

What happened

After resolving via mDNS to a IPv6 LLA, The MQTTX client is unable to connect. It reports retrying. The resolved monitor shows repeatedly occurring name resolution requests.

Expected

Connect to the MQTT-Broker.

Environment

More detail

  • name resolution:

→ Q: mqtt-perimica-hw3kg.local IN A
→ Q: mqtt-perimica-hw3kg.local IN AAAA
← S: success
← A: mqtt-perimica-hw3kg.local IN AAAA fe80::a:ed8a:9f66:8007

@shoe-perinet-io shoe-perinet-io added the bug Something isn't working label Dec 26, 2023
@github-project-automation github-project-automation bot moved this to Backlog in MQTTX Dec 26, 2023
@ysfscream ysfscream moved this from Backlog to TO DO in MQTTX Dec 27, 2023
@ysfscream ysfscream self-assigned this Dec 27, 2023
@ysfscream ysfscream added the desktop MQTTX Desktop label Dec 27, 2023
@ysfscream
Copy link
Member

Hi, @shoe-perinet-io

I'm sorry for not getting back to you sooner.

MQTTX should indeed support connections via IPv6. Could you connect directly using the IPv6 address to troubleshoot your issue further? This might help determine whether the problem lies with the mDNS resolution process or the MQTTX client's handling of IPv6 addresses. Your feedback on this will be critical in identifying and resolving the issue. Thank you for bringing this to our attention.

@ysfscream ysfscream moved this from TO DO to Backlog in MQTTX Jan 2, 2024
@shoe-perinet-io
Copy link
Author

Hi @ysfscream ,
thanks for accepting this issue. Please be advised an IPv6 link local address (LLA) needs to specify the scopeid when connecting to a remote [1]. Let me know, how I can collect further debug information for you, if necessary.

I assume the problem is not in the mDNS resolve process, since my system resolver logs a successful resolved name (resolvectl monitor). This tells me, (1) MQTTX is using the system resolver and (2) MQTTX fails to handle the received IPv6 LLA:

→ Q: mqtt-perimica-hw3kg.local IN A
→ Q: mqtt-perimica-hw3kg.local IN AAAA
← S: success
← A: mqtt-perimica-hw3kg.local IN AAAA fe80::a:ed8a:9f66:8007

I also tested the resolver:

ping -n mqtt-perimica-hw3kg.local

PING mqtt-perimica-hw3kg.local(fe80::a:ed8a:9f66:8007%vpn_softether) 56 data bytes
64 bytes from fe80::a:ed8a:9f66:8007%vpn_softether: icmp_seq=1 ttl=64 time=29.0 ms
64 bytes from fe80::a:ed8a:9f66:8007%vpn_softether: icmp_seq=2 ttl=64 time=13.9 ms
^C
--- mqtt-perimica-hw3kg.local ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 13.948/21.485/29.022/7.537 ms

as well as have verified the glibc resolver is working:

getent ahosts mqtt-perimica-hw3kg.local

fe80::a:ed8a:9f66:8007%5 STREAM mqtt-perimica-hw3kg.local
fe80::a:ed8a:9f66:8007%5 DGRAM
fe80::a:ed8a:9f66:8007%5 RAW

I observed, MQTTX is more chatty when it detects not a terminal at the stdout

./MQTTX-1.9.7.AppImage 2>&1 | cat

[2024-01-02T16:55:26.563] [INFO] default - APP init
[2024-01-02T16:55:29.371] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T16:55:29.372] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://mqtt-perimica-hw3kg.local:8883
[2024-01-02T16:55:29.389] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T16:55:33.396] [INFO] default - mqtt-perimica-hw3kg.local reconnect: 0 times retry
[2024-01-02T16:55:33.435] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T16:55:37.444] [INFO] default - mqtt-perimica-hw3kg.local reconnect: 1 times retry
[2024-01-02T16:55:37.486] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger

I tried to feed unsuccessfully MQTTX the plain IPv6 address, but unfortunately it treated it as a name and tried to resolve the IPv6LLA :

./MQTTX-1.9.7.AppImage 2>&1 | cat

[2024-01-02T17:10:46.127] [INFO] default - APP init
[2024-01-02T17:11:01.649] [INFO] default - mqtt-perimica-hw3kg.local was edited, ID: 92444823-f7a5-48f2-b6ce-7cbf81b6db65
[2024-01-02T17:11:02.299] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:11:02.301] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://fe80::a:ed8a:9f66:8007%vpn_softether:8883
[2024-01-02T17:11:05.500] [WARN] default - MQTTX force close the connection mqtt-perimica-hw3kg.local (clientID mqttx_21706337), reset the reconnect times to 0
[2024-01-02T17:11:05.507] [ERROR] default - mqtt-perimica-hw3kg.local connect fail, MQTT.js onError trigger, Error: getaddrinfo ENOTFOUND fe80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
[2024-01-02T17:11:05.536] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T17:11:27.900] [INFO] default - mqtt-perimica-hw3kg.local was edited, ID: 92444823-f7a5-48f2-b6ce-7cbf81b6db65
[2024-01-02T17:11:28.468] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:11:28.469] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://[fe80::a:ed8a:9f66:8007%5]:8883
[2024-01-02T17:11:32.322] [WARN] default - MQTTX force close the connection mqtt-perimica-hw3kg.local (clientID mqttx_21706337), reset the reconnect times to 0
[2024-01-02T17:11:32.327] [ERROR] default - mqtt-perimica-hw3kg.local connect fail, MQTT.js onError trigger, Error: getaddrinfo ENOTFOUND :8007
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
[2024-01-02T17:11:32.360] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T17:11:45.710] [INFO] default - mqtt-perimica-hw3kg.local was edited, ID: 92444823-f7a5-48f2-b6ce-7cbf81b6db65
[2024-01-02T17:11:46.307] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:11:46.308] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://fe80::a:ed8a:9f66:8007:8883
[2024-01-02T17:11:50.273] [WARN] default - MQTTX force close the connection mqtt-perimica-hw3kg.local (clientID mqttx_21706337), reset the reconnect times to 0
[2024-01-02T17:11:50.278] [ERROR] default - mqtt-perimica-hw3kg.local connect fail, MQTT.js onError trigger, Error: getaddrinfo ENOTFOUND fe80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
[2024-01-02T17:11:50.304] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T17:16:22.961] [INFO] default - mqtt-perimica-hw3kg.local was edited, ID: 92444823-f7a5-48f2-b6ce-7cbf81b6db65
[2024-01-02T17:16:23.543] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:16:23.544] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://fe80:0000:0000:0000:000a:ed8a:9f66:8007:8883
[2024-01-02T17:16:26.813] [WARN] default - MQTTX force close the connection mqtt-perimica-hw3kg.local (clientID mqttx_21706337), reset the reconnect times to 0
[2024-01-02T17:16:26.816] [ERROR] default - mqtt-perimica-hw3kg.local connect fail, MQTT.js onError trigger, Error: getaddrinfo ENOTFOUND fe80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
[2024-01-02T17:16:26.843] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
App closed

I made the extra effort and tried an IPv4 proxy, which made your not IPv6 compliant MQTTX client connect. So there is no issue with the broker, so far.:

socat -d -v TCP4-LISTEN:8883,reuseaddr,fork,bind=127.0.0.1 TCP6:[fe80::a:ed8a:9f66:8007%vpn_softether]:8883

./MQTTX-1.9.7.AppImage 2>&1 | cat

[2024-01-02T17:19:27.657] [INFO] default - APP init
[2024-01-02T17:19:46.601] [INFO] default - mqtt-perimica-hw3kg.local was edited, ID: 92444823-f7a5-48f2-b6ce-7cbf81b6db65
[2024-01-02T17:19:47.224] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:19:47.226] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://::1:8883
[2024-01-02T17:19:50.532] [WARN] default - MQTTX force close the connection mqtt-perimica-hw3kg.local (clientID mqttx_21706337), reset the reconnect times to 0
[2024-01-02T17:19:50.539] [ERROR] default - mqtt-perimica-hw3kg.local connect fail, MQTT.js onError trigger, Error: getaddrinfo ENOTFOUND :8883
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
[2024-01-02T17:19:50.569] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T17:19:59.757] [INFO] default - mqtt-perimica-hw3kg.local was edited, ID: 92444823-f7a5-48f2-b6ce-7cbf81b6db65
[2024-01-02T17:20:00.319] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:20:00.320] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://127.0.0.1:8883
[2024-01-02T17:20:00.338] [WARN] default - MQTTX force close the connection mqtt-perimica-hw3kg.local (clientID mqttx_21706337), reset the reconnect times to 0
[2024-01-02T17:20:00.340] [ERROR] default - mqtt-perimica-hw3kg.local connect fail, MQTT.js onError trigger, Error: connect ECONNREFUSED 127.0.0.1:8883
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
[2024-01-02T17:20:00.349] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
Opening in existing browser session.
[2024-01-02T17:22:32.592] [INFO] default - MQTTX client with ID 92444823-f7a5-48f2-b6ce-7cbf81b6db65 assigned
[2024-01-02T17:22:32.592] [INFO] default - Connect client mqtt-perimica-hw3kg.local, MQTT/SSL connection: mqtts://127.0.0.1:8883
[2024-01-02T17:22:33.143] [INFO] default - mqtt-perimica-hw3kg.local connect success, MQTT.js onConnect trigger
[2024-01-02T17:22:48.449] [INFO] default - mqtt-perimica-hw3kg.local connect close, MQTT.js onClose trigger
[2024-01-02T17:22:48.452] [INFO] default - MQTTX client disconnect, Name: mqtt-perimica-hw3kg.local, client ID: mqttx_21706337

[1] https://labs.ripe.net/author/philip_homburg/whats-the-deal-with-ipv6-link-local-addresses/

@ysfscream
Copy link
Member

Thank you for your detailed information and efforts in diagnosing the issue. The getaddrinfo ENOTFOUND error usually indicates a problem with the DNS resolution process, where the domain name cannot be resolved into an IP address. This can be due to various reasons, such as incorrect domain names, DNS configuration issues, or network connectivity problems.

We will take a closer look into this issue. Your input has been very helpful in pinpointing the potential areas of concern. We appreciate your patience and help in resolving this situation.

@shoe-perinet-io
Copy link
Author

Yes, it does indeed. But please be advised, it only occurred when I was using the IPv6LLA as server destination in the configuration of the MQTT-Broker connection. It did not occurr when I used the fqdn 'mqtt-perimica-hw3kg.local'.

Also, the name of the configuration was, unfortunately, called 'mqtt-perimica-hw3kg.local'. I guess this is misleading. But the actual target can be found with the MQTT/SSL connection: prefix.

  • when I use the mDNS fqdn 'mqtt-perimica-hw3kg.local' as target MQTT/SSL connection: mqtts://mqtt-perimica-hw3kg.local:8883, the connection is closed without any further debug information.
  • when I use the IPV6LLA as target, the MQTT/SSL connection: mqtts://fe80::a:ed8a:9f66:8007:8883, the connection attempt throughs the error Error: getaddrinfo ENOTFOUND fe80. This indicates a wrong behaviour of the MQTTX client, where he tries to resolve 'fe80' since it was not recognized as IPv6 address.
  • when using a proxy with IPv4 endpoint, your MQTTX client does connect.

I strongly think your Client handles the information from the resolver wrongly. It seems not to use the proper API to cover also IPv6 LLA addresses resolved by the system-resolver.

Be advised, the same behaviour can also be observed with Chromium or NodeJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop MQTTX Desktop
Projects
Status: Backlog
Development

No branches or pull requests

2 participants