xHasKx / luamqtt

luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client
https://xhaskx.github.io/luamqtt/
MIT License
160 stars 42 forks source link

Broker drops if i'm only receiving messages and not sending #20

Closed dmitryuv closed 4 years ago

dmitryuv commented 4 years ago

It seems that broker is dropping connection (by design) because ping is sent only when connection is idle (if i read source correctly), but if i'm in receive-only mode and constantly receiving something, then ping may be never sent out. Have you faced this issue? Steps to reproduce – with default settings connect to broker that sends something about every minute, and in ~1.5 minutes you'll be disconnected.

xHasKx commented 4 years ago

Hi @dmitryuv ,

According to MQTT specs (v5 for example), PINGREQ-PINGRESP is used to "Indicate to the Server that the Client is alive in the absence of any other MQTT Control Packets being sent from the Client to the Server."

So if you've subscribed and receiving only QoS 0 messages all time - the client should not send any PUBACK packets and the server is only sending data all time without any response. In this case, the server may decide that client is dead and break the connection.

So I have to change the luamqtt logic to send PINGREQ packets to reset ping-timer only after client packets.

xHasKx commented 4 years ago

Hi @dmitryuv , please check the new version v3.1.2

dmitryuv commented 4 years ago

I've checked latest version – now connection to broker is stable, fix works. Thank you!