Skip to content

mqtt-kafka: a first-time QoS 1 or 2 subscriber may replay messages published before it subscribed #3174

Open

Description

@jfallows

Problem

For a QoS 1 or 2 subscription the subscribe proxy opens a merged Kafka fetch with a consumer group id. In KafkaMergedFactory.onTopicOffsetFetchDataChanged, a group offset of -1 (Kafka's "no committed offset") is mapped to HISTORICAL, so a group with no committed offset resumes at the earliest retained record, not at the live end (found by reading develop at b1a53e9 while investigating whether messages published shortly after a SUBSCRIBE could be lost; not run against a broker, and a script through the mqtt-kafka proxy cannot show it because the scripted Kafka peer supplies the offsets).

If that reading is right, a client that subscribes at QoS 1 or 2 for the first time, with no earlier session state, is sent all messages still retained on the topic from before it subscribed.

MQTT 5.0 section 3.8.4 and section 3.3.1.3 (RETAIN): a new subscription receives the messages published after the subscription is established, plus retained messages according to its Retain Handling option; messages that were published earlier and are not retained are not sent.

Related: the message-loss window between SUBSCRIBE and the first offset commit (#3169) was closed as not reproduced because of this same mapping; its analysis is in that issue.

Expected

  • First decide whether this is wanted behavior; if it is, document it as a deliberate property of the mapping.
  • If not wanted: a QoS 1 or 2 subscription with no committed offset starts at the position the subscription was made, and still resumes from committed offsets afterwards.

First step

Confirm what actually happens with a real Kafka broker or the engine's own test setup: subscribe a new client at QoS 1 to a topic that already holds non-retained records, and observe what is delivered. If the replay does not happen, record the analysis on this issue and close it.

Notes

Found while checking a suspected defect from a clause-by-clause audit of MQTT 3.1.1 and 5.0 conformance. Part of the MQTT conformance work under #512.

Activity

  1. self-assigned this
    on Nov 13, 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