mochi-mqtt / server

The fully compliant, embeddable high-performance Go MQTT v5 server for IoT, smarthome, and pubsub

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect(?) handling of 'retain' flag in MQTT 3.1.1

bkupidura opened this issue · comments

commented

Looks like mochi-co/mqtt is incorrectly setting retain flag for published messages in 3.1.1.

Based on MQTT-3.3.1-9

It MUST set the RETAIN flag to 0 when a PUBLISH Packet is sent to a Client because it matches an established subscription regardless of how the flag was set in the message it received [MQTT-3.3.1-9].

So imho broker after receiving retained message, should store it - but packet should have retain flag set to 0 when publishing to clients, unless packet is really retained (and not live sent).

How mosquitto is handling that:

Scenario 1:

  1. Client-A subscribes to test/test
  2. Client-B sends retained message to test/test
  3. Client-A receives message, but retained flag is 0

Scenario 2:

  1. Client-B sends retained message to test/test
  2. Client-A subscribes to test/test
  3. Client-A receives message, retained flag set to 1

Currently mochi-co/mqtt is always setting retained flag to 1 in publish if packet was send with retained flag set (in mqtt 3.1.1).

https://github.com/mochi-co/mqtt/blob/master/server.go#L809

commented

This should be resolved in v2.2.16, thanks again :)