rabbitmq / rabbitmq-mqtt

RabbitMQ MQTT plugin

Home Page:https://www.rabbitmq.com/mqtt.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

session present flag always set to true

amalikctec opened this issue · comments

Hi

RabbitMQ Version: 3.7.7
RabbitMQ-MQTT Version: 3.7.7

I have come across a bug in the MQTT plugin regarding the 'session present' flag. It seems it is not working correctly in all scenarios. If i understand correctly the session present flag's value depends on the following:

  1. If 'clean session' is set to true then 'session present' is set to false. (this is working as expected).
  2. If 'clean session' is set to false then the value 'session present' depends on whether a session (queue in this case) is present or not.

It seems in the second scenario the 'session present' flag is always true regardless of whether a session (queue) for that clientId is present or not.

This can be seen in the following (node.js) sample that always connects with a new client ID. The host can be switched between 'test.mosquitto.org' and localhost (tested with the latest RabbitMQ docker image).
https://we.tl/CBYBXixjCc

It seems there is code that checks if the queue is declared (using the passive bit) in rabbit_mq_processor. Also checked if its an issue in the rabbitmq AMQP plugin, but that seems to be working properly (again tested using the node.js amqp client). Following is the code snippet i am referring to:

session_present(Channel, ClientId) ->
{_, QueueQ1} = rabbit_mqtt_util:subcription_queue_name(ClientId),
Declare = #'queue.declare'{queue = QueueQ1,
passive = true},
case amqp_channel:call(Channel, Declare) of
#'queue.declare_ok'{} -> true;
_ -> false
end.

Please let me know if you require more information.

Thanks

Bump.
Is this plug-in abandoned? We are looking into using rabbitMQ as an MQTT broker and the above is a critical issues as it causes data loss (the device never syncs state with the broker). Therefore it is a blocker.

Thanks

Let's assume that there's enough evidence to reproduce and try to fit it into 3.7.8.

Great to hear that this plug-in is not abandoned. Please let me know if you guys need anything from our end.
We would like to contribute however we dont currently have in-house erlang expertise. Once in production with this we would like to take more ownership and contribute. In the meanwhile it would be great if you guys can provide a fix.

Thanks

@amalikctec can you please attach your code sample to this issue as a .zip or tarball? Apparently the WeTransfer link is defunct.

Please see attached. You can check the discrepancy by switching the HOST between a RabbitMQ deployment (i am using the official docker image) and the public Mosquitto broker. The response on the connect event is printed out to the console.

Thanks for the code sample @amalikctec!

Thanks for the fix!