-
Notifications
You must be signed in to change notification settings - Fork 42
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
Connect is blocking #23
Comments
@Python1320 , good point. I'll think about how to make connector.connect call non-blocking... |
@Python1320 , I found a way how to use settimeout() on almost all stages of the connection lifetime (except DNS resolving). On the other hand, luamqtt library is built to be small and simple, that's why it does still not have ioloop on all connection stages. Do you still plan to use it in your project? |
I have been struggling with a similar problem, I can't seem to be able to keep a client based on this library connected and listening to the broker for messages without blocking the lua socket. It makes it unusable even in my very simple use case of one publishing client, one listening client with one broker. Am I missing something? |
@rafale77 , currently only TCP Connection opening process is blocking and all next stages is async thanks to ioloop, allowing other MQTT clients to work in the same lua script. |
Yes I did and I observed that it opens a listener and waits for a message. While waiting, it does block my main program's socket activities. |
That's because If you want to run some parallel calculations or network communications in the same script with luamqtt - you have several options:
|
I am slowly trying out https://github.com/flukso/lua-mosquitto but we are still using luamqtt, but with a 2 second timeout on connect and exponential backoff. Keeping things simple and flexible is indeed difficult. In my case I need many things to cooperate at the same time and MQTT freezing the other parts is not acceptable. |
Did you try OpenResty - https://openresty.org/ ? |
Anyway, there is a way to provide a new method in luamqtt to start connecting async like described in #23 (comment) |
@Python1320 The main "connect" problem is here; https://github.com/xHasKx/luamqtt/blob/master/mqtt/luasocket.lua#L12 It uses local sock = socket.tcp()
sock:settimeout(timeout)
local ok, err = sock:connect(host, port) --> calling `connect` on the socket, NOT the library! The call will still be blocking, but at least it will timeout at some point and not just hang. If you use an IP instead of a name, you can take out the DNS resolution call as well. @xHasKx As for using a |
Our broker was recently DDoSed, which caused a disconnect on our luamqtt end, and a reconnect attempt where the connecting routine took over a minute after which our service was automatically killed for being frozen by our watchdog.
The stacktrace showed us that in fact the ioloop is not used for connecting in mqtt:
luamqtt/mqtt/client.lua
Line 730 in 929209a
Is this an oversight or by design? Would a rearchitecturing be out of the question so that connect would be asynchronous also?
(Connect will always block if there is DNS resolving to be done so this may also not be the perfect solution for everyone).
Another option is we could establish a connection ourselves and just provide the connected socket to luamqtt.
The text was updated successfully, but these errors were encountered: