Repository navigation
Description
Problem
Subscribe-side QoS 1 and 2 state and inbound QoS 2 packet ids are kept outside the main session record: in a per-session #offsets record on the sessions topic and in Kafka consumer-group offsets (<prefix>-<clientId>). By reading MqttKafkaSessionFactory and MqttKafkaSubscribeFactory on develop at b1a53e9 (approximate lines ~896 and ~1830-1850 in the session factory; not run):
- At session expiry only the main session record is removed. The
#offsetsrecord and the consumer-group offsets survive, so a later connect with Clean Start=0 (or Clean Session=0) restores stale inbound QoS 2 packet ids and a stale backlog. - A connect with Clean Start=1 (or Clean Session=1) does not reset the consumer-group offsets or the
#offsetsrecord either, so a client that asked for a fresh session can still be sent messages from its previous session's backlog.
MQTT 5.0 section 3.1.2.4 and MQTT 3.1.1 section 3.1.2.4: with Clean Start (Clean Session) set to 1 the client and server discard any existing session and start a new one; a session that has expired is discarded the same way.
Sessions that never expire (Session Expiry Interval 0xFFFFFFFF, and 3.1.1 Clean Session=0 after the recent session persistence fix) make this matter more.
Expected
- A Clean Start=1 (Clean Session=1) connect leaves no consumer-group offsets and no
#offsetsrecord from the previous session; the first subscribe fetch of the new session starts as for a new client. - Session expiry removes the
#offsetsrecord and the consumer-group offsets together with the main session record. - A Clean Start=0 connect to a live session is unchanged.
Test plan (test-first)
Scripts through mqtt-kafka (not a mocked application) for v5 and v4:
- subscribe at QoS 1 and 2, receive and acknowledge part of the backlog, disconnect, reconnect with Clean Start=1: no replay of the old backlog, no stale packet ids, and the Kafka side shows the offsets reset;
- the same, but with the session expiring instead of a Clean Start=1 reconnect;
- Clean Start=0 reconnect to a live session still resumes from the committed offsets.
The first commit contains the failing scripts. If any part of the described behavior cannot be shown to fail, say which and why on this issue instead of changing code for it.
The implementation must follow how the module already creates, commits and resets consumer-group offsets and session records; if no established pattern fits for resetting group offsets, ask before inventing one.
Notes
Found by a clause-by-clause audit of MQTT 3.1.1 and 5.0 conformance, by reading the code. Consumer groups remain the home of subscribe-side QoS state for now. Part of the MQTT conformance work under #512.
Activity
jfallows commentedon Nov 12, 2026
Findings so far on this issue, from scripts through
mqtt-kafkaagainst unchanged code at b1a53e9:<clientId>#offsetsbehind: confirmed. The four expiry scenarios (session.close.expire.session.state,session.abort.expire.session.state,session.expiry.after.signal.stream.restart,session.ignore.non.fetch.signal.stream.flush) now expect a tombstone for<clientId>#offsetsafter the session tombstone. All four fail inMqttKafkaSessionProxyITbecause that tombstone is never produced. The fix is a second tombstone in the expiry path.#offsetsrecord: not failing. A new scenariosession.clean.start.discard.offsetsserves a staleclient#offsetsrecord with packet ids 1 to 3 and producer 12345. A Clean Start=1 connect ignores it, initializes a new producer, and writes a fresh#offsetsrecord with new offsets and no packet ids. It passes on unchanged code, so no code changes for this part.Generated by Claude Code