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

libmosquitto: Long delay in mosquitto_connect() on Arm64 #2955

Open
shiftee opened this issue Nov 22, 2023 · 6 comments
Open

libmosquitto: Long delay in mosquitto_connect() on Arm64 #2955

shiftee opened this issue Nov 22, 2023 · 6 comments

Comments

@shiftee
Copy link

shiftee commented Nov 22, 2023

Hi,

I am working on a PinePhone app which uses libmosquitto.

It works fine on my x86_64 development machine.
Running on the phone (mobian/bookworm) it waits in mosquitto_connect() for ~129s before opening the TCP connection.

This issue also seems to be present in the latest mosquitto git:

$ ./client/mosquitto_pub -h test.mosquitto.org -m "testmsg" -t "this/is/a" -d
Client null sending CONNECT
Error: Keepalive exceeded

It works with a 3 minute keepalive:

$ ./client/mosquitto_pub -h test.mosquitto.org -m "testmsg" -t "this/is/a" -d -k 180
Client null sending CONNECT
Client null received CONNACK (0)
Client null sending PUBLISH (d0, q0, r0, m1, 'this/is/a', ... (7 bytes))
Client null sending DISCONNECT
@shiftee
Copy link
Author

shiftee commented Nov 22, 2023

Okay it looks like the issue is in net__try_connect_tcp()

mosquitto_connect()
    mosquitto_connect_bind()
        mosquitto_connect_bind_v5()
            mosquitto__reconnect()
                net__socket_connect()
                    net__try_connect()
                        net__try_connect_tcp()

getaddrinfo() is returning the following addresses for test.mosquitto.org

  • 0.0.0.0
  • 91.121.93.94

0.0.0.0 is passed to connect() first and takes up all the time.

On my x86_64 desktop the same addresses are returned but in the opposite order, so the problem is not seen.

@karlp
Copy link
Contributor

karlp commented Nov 22, 2023

so what's giving you the 0.0.0.0 response? that's obviously garbage... (andentirely within yourown resolver setup...)

@shiftee
Copy link
Author

shiftee commented Nov 23, 2023

Both addresses are appearing on Mobian Bookworm and Ubuntu 23.04 at my home.
Both also appear on a SLES15 SP4 server at my workplace which has no relation to my DNS.

It looks to me like getaddrinfo() is including 0.0.0.0 when it shouldn't.

The below zipped patch prints all returned addresses, give it a try if you have time:
0001-Print-the-ip-addresses-from-getaddrinfo.zip

@shiftee
Copy link
Author

shiftee commented Nov 23, 2023

Okay, the 0.0.0.0 values are what you get if you pass IPV6 addresses to inet_ntoa().

Using inet_ntop() I get the following:
::2001:41d0:1:925e:0:0
91.121.93.94

I cannot ping that IPv6 address from home, work or this site: https://www.ipvoid.com/ipv6-ping-test

Can you look into that please?

@karlp
Copy link
Contributor

karlp commented Nov 23, 2023

sounds like your system believes it can do v6, but it actually can't? That site works for me to ping "test.mosquitto.org"

PING test.mosquitto.org(2001:41d0:1:925e::1 (2001:41d0:1:925e::1)) 56 data bytes
64 bytes from 2001:41d0:1:925e::1 (2001:41d0:1:925e::1): icmp_seq=1 ttl=54 time=73.6 ms
64 bytes from 2001:41d0:1:925e::1 (2001:41d0:1:925e::1): icmp_seq=2 ttl=54 time=73.6 ms
64 bytes from 2001:41d0:1:925e::1 (2001:41d0:1:925e::1): icmp_seq=3 ttl=54 time=72.6 ms

--- test.mosquitto.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 72.551/73.251/73.619/0.495 ms

Note that your resolver is giving you this invalid " ::2001:41d0:1:925e:0:0" not the actual AAAA response tooo...

;; ANSWER SECTION:
test.mosquitto.org.	3583	IN	AAAA	2001:41d0:1:925e::1

@shiftee
Copy link
Author

shiftee commented Nov 23, 2023

It looks like the returned addresses are correct and were simply being formatted incorrectly.
The interfaces are a bit tricky and I am not familiar with them, sorry.
But indeed IPv6 is not working from my phone.
I guess I need to fix it, or prevent IPV6 addresses from being returned from DNS.
Sorry for the trouble and thanks for the help.

If I had known an IPv6 address was being used then this ticket would probably not have been opened.
What do you think of adding something like the commit below?
log__printf() requires the mosq param though.
Would it be acceptable to pass mosq down from net__socket_connect() to net__try_connect_tcp()?

shiftee@eb2bdcf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants