Skip to content

mqtt: Retain Handling 1 is treated as Retain Handling 2 #3151

Closed

Description

@jfallows

Problem

MQTT 5.0 [MQTT-3.3.1-10]: when the Retain Handling subscription option is 1, the server MUST send the retained messages matching the filter if the subscription did not already exist, and MUST NOT send them if it did.

MqttServerFactory sets the send-retained flag only for Retain Handling 0 (subscription option decoding, about lines 5579-5596 on develop at 1e802cb). For value 1 no flag is set, so a retained message is never sent. That is right for value 2 and for a subscription that already existed, and wrong for a new subscription with value 1.

Expected

  • Retain Handling 1: retained messages are replayed when the filter was not already part of the session's subscriptions before this SUBSCRIBE, and not replayed when it was.
  • Retain Handling 0 (always replay) and 2 (never replay) are unchanged, and value 3 stays a protocol error.
  • The session state already holds the existing subscriptions, so this needs no change on the Kafka side.
  • MQTT 3.1.1 has no Retain Handling; its behavior is unchanged.

Test plan (test-first)

v5 network and application scripts, run through the runtime ITs:

  • Retain Handling 1 on a new filter replays the retained message;
  • Retain Handling 1 on a SUBSCRIBE of a filter the session already has does not replay;
  • Retain Handling 0 on a re-subscribe still replays; Retain Handling 2 never replays.

The first commit contains the failing scripts.

Notes

Found by a clause-by-clause conformance audit, by reading the code. Part of the MQTT conformance work under #512.

Activity

  1. self-assigned this
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions