Repository navigation
fix(binding-mqtt-kafka): complete a session offset commit when kafka acknowledges it - #3347
Merged
Merged
Conversation
This was referenced Nov 18, 2026
…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
force-pushed
the
fix/3303-mqtt-kafka-qos2-session-commit-ack
branch
from
November 20, 2026 03:06
6177cbe to
36cc74f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
MqttKafkaSessionFactorytreated 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, becauseonOffsetCommitAckwas guarded byisEmpty(), 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
unfinishedSeqsfrom #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
4cf427280adds the scenariopublish.qos2.complete.after.acknowledge: an mqtt pair and a kafka pair, withMqttIT.shouldPublishQoS2CompleteAfterAcknowledge,KafkaIT.shouldPublishQoS2CompleteAfterAcknowledgeandMqttKafkaPublishProxyIT.shouldSendMessageQos2CompleteAfterAcknowledge.expected: read abortedbutwas: read advised, the early PUBCOMP flush.6177cbeef) it passes.Verification
./mvnw clean installonspecs/binding-mqtt-kafka.spec(checkstyle, jacoco):MqttIT196 andKafkaIT225 pass../mvnw clean verifyonruntime/binding-mqtt-kafka(checkstyle, jacoco): 245 ITs pass (MqttKafkaPublishProxyIT49,MqttKafkaSessionProxyIT73,MqttKafkaSubscribeProxyIT123) and 105 unit tests pass.examples/mqtt.kafka.proxywith an image built from developaaeadf5ecand from this branch,apache/kafka:4.1.1,mosquitto_pubMQTT 5, with a temporary trace of the session commit windows (not committed).seq=1298 ack=649(credit-only) and thenack=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.seq=1298 ack=649) leavesunacked=1and releases nothing. The windowack=1298releases the packet and the client gets PUBCOMP RC:0.device/q2.Not delivered
aaeadf5ec. Re-run on an image built from that commit: after a warm-up publish,printf 'm1\nm2\nm3\nm4\nm5\n' | mosquitto_pub -V mqttv5 -q 2 -lstops the engine withNullPointerException: Cannot invoke "KafkaDataExFW.merged()" because "kafkaDataEx" is nullatKafkaMergedFactory$KafkaMergedStream.onMergedInitialData(KafkaMergedFactory.java:1262). The client retransmits and the example restarts Zilla, so it repeats (11 times in about 10 s). None of the 5 messages gets a PUBREC. This PR does not change that, and it is the reason mqtt-kafka: a QoS 2 PUBLISH crashes the engine (NoSuchElementException in KafkaOffsetCommitStream.onKafkaWindow) #3303 stays open. A QoS 2 message is sent to Kafka as an INIT fragment and its FIN follows only after the commit acknowledgement, so a second PUBLISH can interleave on the same stream. No fix or test for it is included, and no issue has been filed.Generated by Claude Code