Open detly opened 4 years ago
I tried using your main_poll_readwrite.c code, thanks for providing that.
For the mosquitto config I used:
listener 8883
cafile ../test/ssl/all-ca.crt
certfile ../test/ssl/server.crt
keyfile ../test/ssl/server.key
password_file pw
Those certificates are in the mosquitto repository. I configured your tool to point to all-ca.crt, localhost, and set the username and password. That worked fine.
I then tweaked main_poll_readwrite.c to use connect_async instead, and reran it with the same results:
I tried generating a self-signed certificate instead, and that worked as well.
Ah thanks. I'll try it with a local server and your config there and see if I can reproduce it. For the Mosquitto client were you using a release or master?
I used 1.6.12 from the Ubuntu PPA. The broker was the fixes
branch I think, but really there's no difference to that and what's in 1.6.12.
On Tue, 8 Sep 2020 at 08:22, Roger Light notifications@github.com wrote:
I used 1.6.12 from the Ubuntu PPA. The broker was the fixes branch I think, but really there's no difference to that and what's in 1.6.12.
I finally got around to testing it, and it works perfectly fine (a) over localhost and (b) over my LAN. It's only our remote host that triggers this behaviour. I'll debug it with our server folk, but do you know what version of LibUV you used for this?
I'm struggling to think of how any behaviour from a remote server could make Linux or LibUV think a socket is constantly in need of being written to, but it doesn't look like it's Mosquitto, so sorry for the noise!
Cheers, Jason
On Thu, 17 Sep 2020 at 12:20, Jason Heeris jason.heeris@gmail.com wrote:
I finally got around to testing it, and it works perfectly fine (a) over localhost and (b) over my LAN.
15 seconds after sending this I managed to reproduce it on LAN! But it took a few tries, and might be intermittent or timing related. Also it used an older version of Mosquitto (1.4.15 from the Ubuntu 18.04.1 repos), but our server isn't actually using Mosquitto at all so I don't think it matters (or maybe it does, but would point to a similar issue in our own setup?).
This is what I see on the server (192.168.1.100):
$ mosquitto -c server_conf
1600309396: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22
-0300) starting
1600309396: Config loaded from server_conf.
1600309396: Opening ipv4 listen socket on port 8883.
1600309396: Opening ipv6 listen socket on port 8883.
1600309396: Warning: Address family not supported by protocol
1600309398: New connection from 192.168.1.231 on port 8883.
1600309401: Socket error on client
Note those first three connections: socket error on client
Anyway, if you have the time, please let me know if you can get this to happen when there's an extra hop between your client and server.
Cheers, Jason
Before I try to reproduce/debug this in v2, I want to check a couple of things:
mosquitto_connect_async()
if I'm doing my own event handling ie. I must use mosquitto_loop_start()
. Is this still true?mosquitto_connect()
had some way to cancel an ongoing connection attempt. At the moment, under Linux's default TCP settings, it takes about 2 mins for a connect call to resolve to success or failure, which makes it impossible to implement a timeout in some other way (eg. running it in LibUV's threadpool and cancelling it from a timer won't work, because there's no way to cancel an ongoing blocking operation). Is there a way to cancel a connect call, or could there be one?Confirmed this is still an issue on 2.0.10.
bring libuv & libevent support will be a good start.
(I'm using Mosquitto 1.6.12 from the PPA on Ubuntu 20.04 and Libuv 1.34.2.)
I'm trying to integrate the Mosquitto client API with the Libuv event loop. For the most part it's gone fine - I can get the socket with
mosquitto_socket()
, create a Libuv poll handle from it and get single threaded event driven code. Even the most minimal example I could write is a bit lengthy, so I've put it up on Gitlab.The outline of what I'm doing is:
Before starting the loop:
mosquitto_new()
, set up client details, callmosquitto_connect()
mosquitto_socket()
libuv uv_poll_t
with the socket, firing when the socket is readable or writable (initially)mosquitto_loop_misc()
periodicallyI then start the loop and:
mosquitto_read()
, andmosquitto_write()
ifmosquitto_wants_write()
is truemosquitto_wants_write()
mosquitto_loop_misc()
This all works fine, and is what's in the Gitlab project. Here's what my logging shows when I run it:
The only issue is that the
mosquitto_connect()
call is blocking. In theory, it can return before the connection is actually established, and usually does — I don't see theCONNACK
until the first poll (write?) callback. That's fine. But if I use eg. netem under Linux to silently drop packets, the connect call seems to block indefinitely.The docs say not to use
mosquitto_connect_async()
unless I'm usingmosquitto_loop_start()
, but then I found a comment on1791 which says that it's fine. So I tried switching to that, but immediately encountered a problem where
mosquitto_wants_write()
always returns true, so my poll handler fires on every run of the libuv loopMy logs now look like:
Now, my server uses TLS on port 8883 with a self-signed certificate (due to no domain name) and username/password authentication. I tried to test this issue on
test.mosquitto.org
but (a) I couldn't get TLS to work (maybe an expired certificate?) and (b) it doesn't allow for username/password auth. Testing with no encryption on 1883, I couldn't reproduce the issue, so I think it has something to do with one of those extra factors.(I originally posted this on the mailing list but I'm more certain now that this is at the very least an enhancement request for a non-blocking
connect()
API and should go here.)