Skip to content

fix(binding-mqtt-kafka): complete a session offset commit when kafka acknowledges it - #3347

Merged
jfallows merged 2 commits into
developfrom
fix/3303-mqtt-kafka-qos2-session-commit-ack
Nov 20, 2026
Merged

jfallows merged 2 commits into
developfrom
fix/3303-mqtt-kafka-qos2-session-commit-ack

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

Refs #3303

Follow-up to #3309. It does not close #3303: closing waits for confirmation that the benchmark no longer sees the problem.

Root cause

MqttKafkaSessionFactory treated every window after the session offset commit stream opened as the acknowledgement of its oldest commit. The Kafka produce path grows the stream maximum while it holds the acknowledge, so a window that only grants credit released a PUBCOMP, or created the session stream, before Kafka had acknowledged the commit. It is the same idiom #3309 fixed on the publish offset commit stream. Here it does not crash, because onOffsetCommitAck was guarded by isEmpty(), so the early release was silent.

The fix records the stream position at the end of each PUBREL completion commit and releases the PUBCOMP of the commits whose position the acknowledge has reached, mirroring unfinishedSeqs from #3309. The seed commit is the only commit outstanding until the session stream is created, so the session stream is created once the acknowledge reaches the stream sequence. No new flag is added.

Tests first

  • 4cf427280 adds the scenario publish.qos2.complete.after.acknowledge: an mqtt pair and a kafka pair, with MqttIT.shouldPublishQoS2CompleteAfterAcknowledge, KafkaIT.shouldPublishQoS2CompleteAfterAcknowledge and MqttKafkaPublishProxyIT.shouldSendMessageQos2CompleteAfterAcknowledge.
  • The Kafka server holds the PUBREL completion commit unacknowledged, sends a credit-only window and then aborts the commit stream. The mqtt client expects the session stream to be aborted with no PUBCOMP flush before it. The scenario uses the stream order on the mqtt session stream, so it has no timing dependence.
  • Before the fix, the runtime IT fails with expected: read aborted but was: read advised, the early PUBCOMP flush.
  • After the fix (6177cbeef) it passes.

Verification

  • ./mvnw clean install on specs/binding-mqtt-kafka.spec (checkstyle, jacoco): MqttIT 196 and KafkaIT 225 pass.
  • ./mvnw clean verify on runtime/binding-mqtt-kafka (checkstyle, jacoco): 245 ITs pass (MqttKafkaPublishProxyIT 49, MqttKafkaSessionProxyIT 73, MqttKafkaSubscribeProxyIT 123) and 105 unit tests pass.
  • Real broker: examples/mqtt.kafka.proxy with an image built from develop aaeadf5ec and from this branch, apache/kafka:4.1.1, mosquitto_pub MQTT 5, with a temporary trace of the session commit windows (not committed).
    • Before the fix: for the PUBREL completion commit the windows were seq=1298 ack=649 (credit-only) and then ack=1298. The first one released the packet (unacked=1) and the PUBCOMP was sent before Kafka acknowledged the commit. For the seed commit, the first window (seq=649 ack=0) arrived with the session stream still unseeded.
    • After the fix: the credit-only window (seq=1298 ack=649) leaves unacked=1 and releases nothing. The window ack=1298 releases the packet and the client gets PUBCOMP RC:0.
    • Single QoS 2 publish: PUBREC, PUBREL, PUBCOMP RC:0, one record with key device/q2.
    • Five QoS 2 publishes in a row on one connection, each waiting for the previous to complete: 5 PUBCOMP RC:0 and 5 records for the key.
    • Eight concurrent connections: 8 of 8 PUBCOMP RC:0, one record per key, no engine stop.

Not delivered


Generated by Claude Code

…knowledges the offset commit

Kafka grows the maximum of the session offset commit stream, which holds the
PUBREL completion unacknowledged, and then aborts the stream. The MQTT session
stream must carry no PUBCOMP flush before the abort. The runtime IT fails
against the current proxy: the credit-only window is taken as the
acknowledgement, so the PUBCOMP flush precedes the abort.

Refs #3303

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTq7qqb5tJqF7DRxHv
…acknowledges it

The session offset commit stream treated every window after it opened as the
acknowledgement of its oldest commit. The Kafka produce path grows the stream
maximum while it holds the acknowledge, so a window that only granted credit
released a PUBCOMP, or created the session stream, before Kafka had
acknowledged the commit.

Record the stream position at the end of each PUBREL completion commit and
release the PUBCOMP of the commits whose position the acknowledge has reached,
as the publish offset commit stream does. The seed commit is the only commit
outstanding until the session stream is created, so the session stream is
created once the acknowledge reaches the stream sequence.

Refs #3303

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTq7qqb5tJqF7DRxHv
@jfallows
jfallows force-pushed the fix/3303-mqtt-kafka-qos2-session-commit-ack branch from 6177cbe to 36cc74f Compare November 20, 2026 03:06
@jfallows
jfallows merged commit 1194055 into develop Nov 20, 2026
53 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: a QoS 2 PUBLISH crashes the engine (NoSuchElementException in KafkaOffsetCommitStream.onKafkaWindow)

2 participants