Skip to content

fix(binding-mqtt-kafka): act on session offsets fetch only once - #3119

Merged
jfallows merged 1 commit into
developfrom
fix/3103-mqtt-kafka-offset-fetch-once
Nov 17, 2026
Merged

jfallows merged 1 commit into
developfrom
fix/3103-mqtt-kafka-offset-fetch-once

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

Reconnecting with a client id whose session offsets record already exists could fail the new connection with CONNACK reason code 0x8E (session taken over).

Root cause. The session offsets fetch stream (mqtt-sessions, key <client>#offsets) delivers the prior offsets record and then a caught-up flush. Both notifications ran offset fetch completion in MqttKafkaSessionFactory, so the session started a second producer init and a second offset commit stream. The first commit stream's WINDOW then triggered the offsets write on the second stream, which had no credit yet, so the merged kafka stream reset it. The reset carries no reason, which the mqtt server maps to 0x8E.

Fix. Offset fetch completion runs once per session, keyed on the pending offset fetch stream (the existing offsetFetch field), so later notifications from the same fetch stream are ignored.

Test evidence.

  • New scenario session.qos2.offset.fetch.data.then.caught.up: k3po pair, spec-level KafkaIT/MqttIT methods, and a runtime MqttKafkaSessionProxyIT method. The runtime IT failed before the fix (a second producer init stream is started) and passes after.
  • ./mvnw clean verify of specs/binding-mqtt-kafka.spec and runtime/binding-mqtt-kafka passes, including checkstyle and license checks.
  • Real Kafka, examples/mqtt.kafka.proxy image built from this branch, MQTT 5 raw client doing CONNECT, DISCONNECT, immediate CONNECT with the same client id. Clean Start 1, before: 5-14 of 100 reconnects got 0x8E; after: 0 of 350 (plus 0 of 100 with Clean Start 0 and 0 of 50 with a 200 ms gap).

Fixes #3103


Generated by Claude Code

The session offsets fetch stream can deliver the prior offsets record and
then a caught-up flush. Each notification ran offset fetch completion, so
a reconnect with an existing offsets record started a second producer init
and a second offset commit stream. The first commit stream's window then
triggered a write on the second, which had no credit, and the merged stream
reset the session, surfacing as a CONNACK with reason code 0x8E.

Offset fetch completion now runs once per session, keyed on the pending
offset fetch stream.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoY2kh8WfqLyYj85hqP
@jfallows
jfallows force-pushed the fix/3103-mqtt-kafka-offset-fetch-once branch from b536f18 to 170a3f5 Compare November 17, 2026 01:21
@jfallows
jfallows merged commit 906e229 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: reusing a client id right after disconnect can briefly fail to connect

2 participants