Skip to content

fix(binding-mqtt-kafka): reset the group offsets on Clean Start when publish.qos.max is below 2 - #3273

Merged
jfallows merged 8 commits into
fix/3271-mqtt-kafka-request-stream-creditfrom
fix/3205-mqtt-kafka-clean-start-qos-max
Nov 17, 2026
Merged

jfallows merged 8 commits into
fix/3271-mqtt-kafka-request-stream-creditfrom
fix/3205-mqtt-kafka-clean-start-qos-max

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

On Clean Start=1 the session deletes the committed offsets of the consumer group <groupIdPrefix>-<clientId> before the new session is established (#3170, #3202), but only on the path taken when publish.qos.max is 2. For a binding with publish.qos.max below 2 the session never fetched the partitions, so OffsetDelete had nothing to name and a client that connected with Clean Start=1 was still sent the backlog of its previous session.

A Clean Start on a binding with publish.qos.max below 2 now fetches the partitions of the messages and retained topics, runs FindCoordinator and OffsetDelete for the group of the client, and only then replies to the client, as the QoS 2 path does. A failed reset is not retried and never fails the connect. The reset reuses the group offsets reset that runs when a session expires (#3204), including waiting for one already in progress for the same client id.

This adds latency to a Clean Start connect when publish.qos.max is below 2: the reply to the client waits for the partition lookup, FindCoordinator and OffsetDelete.

Stacked on #3272 (base fix/3271-mqtt-kafka-request-stream-credit), which is stacked on #3267.

Fixes #3205

Specification statements

Read in full: MQTT v5.0 3.1.2.4 and 4.1 (with 4.1.1), MQTT v3.1.1 3.1.2.4, and the Kafka protocol definitions of OffsetDelete (key 47, v0) and FindCoordinator (key 10, v3). Not read in full: the rest of both MQTT specifications, the rest of the Kafka protocol page, and the diff of #3202.

  • v5.0 3.1.2.4 [MQTT-3.1.2-4]: "If a CONNECT packet is received with Clean Start is set to 1, the Client and Server MUST discard any existing Session and start a new Session."
  • v3.1.1 3.1.2.4 [MQTT-3.1.2-6]: "If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new one. ... State data associated with this Session MUST NOT be reused in any subsequent Session." The same section says "When CleanSession is set to 1 the Client and Server need not process the deletion of state atomically."
  • v5.0 4.1: the Session State in the Server includes "QoS 1 and QoS 2 messages pending transmission to the Client" and those "sent to the Client, but have not been completely acknowledged"; here that state is the group offsets.
  • Kafka OffsetDelete v0 takes group_id [topics => name [partitions => partition_index]], so the partitions must be named.

The discard obligation does not depend on publish.qos.max, so the reset is needed on this path as well.

Changes

  • A Clean Start session on a binding with publish.qos.max below 2 registers a group offsets reset for the client id, waits for it (the existing awaitedReset wait), and then starts the session, so the reply to the client follows the OffsetDelete.
  • Mirrored from fix(binding-mqtt-kafka): delete the group offsets of a session when it expires #3267: KafkaGroupOffsetsReset, groupOffsetsResets and awaitedReset. The reset is created through a new newGroupOffsetsReset helper, which the session expiry reset now also uses, and doOpenMetas takes the authorization of the session (the expiry reset passes 0 as before).
  • Changed on fix(binding-mqtt-kafka): delete the group offsets of a session when it expires #3267's reset path: the topic set of a reset is built in one place, resolveMessagesTopics, used by the session expiry reset, the QoS 2 Clean Start and the below-2 Clean Start. It leaves out routes whose messages topic is parameterized, which cannot be resolved without a publish topic and previously made the build of the topic set throw. This was shown on the wire for the session expiry reset and the below-2 path before the guard (shouldResetGroupOffsetsOnSessionExpiryWhenMessagesWithParams, shouldRejectPublishWhenTopicSpaceWithParams). The QoS 2 Clean Start path cannot run for such a binding, because the effective publish.qos.max is capped at 1 when a route has a parameterized messages topic, so nothing changed there beyond using the helper.

Tests

First commit (failing): the four existing Clean Start scenarios on the below-2 path now expect the meta streams, FindCoordinator and OffsetDelete: session.close.reconnect.clean.start, session.will.message.clean.start, session.will.message.clean.start.abort.zero.window and publish.reject.qos2 (with the at_least_once config), plus a new coordinator-not-available scenario (session.clean.start.qos.max.1 with session.clean.start.reset.group.offsets.coordinator.not.available.qos.max.1). All five failed against the previous code because the scripted meta streams were never opened. They are in the existing IT classes (KafkaIT, MqttIT, MqttKafkaSessionProxyIT); no new IT class.

session.will.message.clean.start.abort.zero.window grants every kafka stream a window of 67, which is smaller than the OffsetDelete request, so it stayed red until #3272 made the request wait for credit. It is unchanged from the first commit and passes with #3272 merged.

Result of a clean verify of the touched modules with module checks on and the build cache skipped, with #3272 merged:

  • specs/binding-mqtt-kafka.spec: MqttIT 130 tests, KafkaIT 163 tests, 0 failures, 0 checkstyle violations.
  • runtime/binding-mqtt-kafka: 169 tests (MqttKafkaSessionProxyIT 54, MqttKafkaPublishProxyIT 45, MqttKafkaSubscribeProxyIT 70, unit tests 10), 0 failures, 0 checkstyle violations.

Not delivered

  • The group offsets of a parameterized messages topic are not deleted by any reset (session expiry, QoS 2 Clean Start or below-2 Clean Start), because the topic cannot be resolved without a publish topic.
  • No below-2 variants of the other failure scripts (broker zero, group not found, partition error, negotiated version); only coordinator-not-available is added. The failure handling is the shared reset's, which the QoS 2 scripts already cover.

Generated by Claude Code

…an Start when publish.qos.max is below 2

Four existing Clean Start scenarios on a binding with publish.qos.max below 2
now expect the meta streams, FindCoordinator and OffsetDelete before the
session is established, and a coordinator-not-available scenario covers a
failed FindCoordinator on the same path. They fail against the current code,
which never fetches the partitions on this path.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTqxGohHBU4VramnU
…publish.qos.max is below 2

A Clean Start session on a binding with publish.qos.max below 2 now fetches
the partitions of the messages and retained topics, runs FindCoordinator and
OffsetDelete for the consumer group of the client, and only then replies to
the client, as the QoS 2 path does. A failed reset is not retried and never
fails the connect.

The reset reuses the group offsets reset that runs when a session expires,
including waiting for one already in progress for the same client id.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTqxGohHBU4VramnU
…fsets reset only when it runs

Resolving the messages topics of every route when a session is created fails
for a route whose messages topic uses parameters, which broke sessions that
never reset the group offsets. The topics are now resolved when the Clean Start
reset starts, through the same helper as the QoS 2 path and the signal stream.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTqxGohHBU4VramnU
… group offsets reset paths

A route whose messages topic uses parameters cannot be resolved without a
publish topic. The session expiry reset and the QoS 2 Clean Start reset throw
while building the topic set for such a route.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTqxGohHBU4VramnU
…ding the group offsets reset topics

A route whose messages topic uses parameters cannot be resolved without a
publish topic, so resolving it while building the topics of a group offsets
reset threw. The topic set is built in one place for the session expiry reset
and the Clean Start reset, and now leaves such routes out, so the group offsets
of those topics are not deleted.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTqxGohHBU4VramnU
…meterized messages topic

The effective publish.qos.max is capped at 1 when a route has a parameterized
messages topic, so the QoS 2 Clean Start path cannot run for such a binding.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTqxGohHBU4VramnU
…am-credit' into fix/3205-mqtt-kafka-clean-start-qos-max
…am-credit' into fix/3205-mqtt-kafka-clean-start-qos-max
@jfallows
jfallows merged commit 056b116 into develop Nov 17, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mqtt-kafka: reset the group offsets on Clean Start when publish.qos.max is below 2

2 participants