Repository navigation
fix(binding-mqtt-kafka): complete a qos2 offset commit when kafka acknowledges it - #3309
Merged
Merged
Conversation
…edit-only window The offset commit produce stream may grow its maximum while it holds its acknowledge before it acknowledges the commit. The new scenario sends such a window ahead of each acknowledgement on the publish offset commit stream. The runtime IT fails against the current proxy with a NoSuchElementException from KafkaOffsetCommitStream.onKafkaWindow, which stops the engine. The existing publish.qos2 scenario never sent that window: it acknowledges each commit with exactly one window, so every window was an acknowledgement. Refs #3303 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
…nowledges it The publish offset commit stream completed one queued commit for every window it received after opening, so a window that only granted credit consumed a queued commit before Kafka had acknowledged it, and the acknowledging window that followed found the queue empty and stopped the engine. Record the stream position at the end of each commit and complete the queued commits whose position the acknowledge has reached, as the QoS 1 publish does with its unacknowledged sequences. A credit-only window completes nothing. Fixes #3303 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
jfallows
pushed a commit
to aklivity/mqtt-benchmark
that referenced
this pull request
Nov 24, 2026
* Run Zilla 2.8.0-rc8 by default 2.8.0-rc8 includes aklivity/zilla#3540, which fixes the JVM crash in the Kafka cache's produce-side segment compaction (aklivity/zilla#3536), and the QoS 2 fix from aklivity/zilla#3309. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Remove Zilla issue notes from the README and the QoS 2 delivery check Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop the stale shared subscription note and reword the lower connection rate scenarios Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Fixes #3303
Root cause
KafkaOffsetCommitStream.onKafkaWindowcompleted one queued commit for every WINDOW it received after the stream opened. The Kafka produce path grows the stream maximum while it holds the acknowledge, so a QoS 2 commit is followed by a credit-only window (ack=0 max=33419) and later by the acknowledging window (ack=651 max=32768). The credit-only window consumed the queued commit before Kafka had acknowledged it, and the acknowledging window found the queue empty and stopped the engine.The fix mirrors
MqttPublishProxy.unackedSeqsin the same class (the QoS 1 path): record the stream position at the end of each commit and complete the queued commits whose position the acknowledge has reached. A credit-only window completes nothing.Introducing change: not established. The credit-only window comes from the Kafka produce path, which
git logshows unchanged since 2.6.1. I reverted theKafkaCacheServerProduceFactoryhunk of #3295 and the #3300 batching change in turn, rebuilt the image and re-ran the issue's command. Both still crashed with the identical window sequence, so neither is the cause. The released 2.7.1 image completes the same QoS 2 publish. I did not bisect further.Tests first
6fadc64fbadds the scenariopublish.qos2.offset.commit.credit.windowwithKafkaIT.shouldPublishQoS2MessageOffsetCommitCreditWindow(client and server scripts run against each other) andMqttKafkaPublishProxyIT.shouldSendMessageQos2OffsetCommitCreditWindow.NoSuchElementExceptionfromLinkedList.removeinMqttKafkaPublishFactory$KafkaOffsetCommitStream.onKafkaWindow:2136, thenAgentTerminationException.554951889) it passes.option zilla:window 8192in the default update mode. k3po answers each DATA with exactly one window whose acknowledge covers it, so every window was an acknowledgement and the queue and windows always matched 1:1. The new scenario usesoption zilla:update "handshake"and sendsread option zilla:window(maximum grows, acknowledge held) beforeread option zilla:ack. Under handshake mode the scenario also acknowledges the session stream and the messages stream explicitly (a QoS 2 data frame reserves the whole 8192 window, so its acks are 8192 and 16384).Verification
./mvnw clean installonspecs/binding-mqtt-kafka.spec(checkstyle, jacoco):MqttIT170 andKafkaIT200 pass../mvnw clean verifyonruntime/binding-mqtt-kafka(checkstyle, jacoco): 212 ITs pass, includingMqttKafkaPublishProxyIT48 (QoS 0, QoS 1 and the existing QoS 2 scenarios unchanged) and the new method; unit tests 29 pass.examples/mqtt.kafka.proxywith an image built from this branch,apache/kafka:4.1.1,mosquitto_pubMQTT 5.d8cac978c):mosquitto_pub -q 2 -t device/q2givesNoSuchElementExceptionatonKafkaWindow(MqttKafkaPublishFactory.java:2136)andENGINE_STOPPED.device/q2inmqtt-devices.mqtt-devicesholds 5 records for the key.Not delivered
mosquitto_pub -lsending several PUBLISHes without waiting for PUBREC): with this change the engine stops with an NPE inKafkaMergedFactory$KafkaMergedStream.onMergedInitialData(kafkaDataExis null, a FIN-only frame arrives with no message in progress). The released 2.7.1 image does not crash here but also never sends PUBREC, so the client retransmits indefinitely. This looks like a separate defect: a QoS 2 message is sent to Kafka as an INIT fragment now and its FIN much later, so a second PUBLISH can interleave. I did not investigate it further and have not filed an issue.MqttKafkaSessionFactory:onOffsetCommitAcktreats every window after the stream opens as an acknowledgement of the oldestunackedPacketIdsentry, guarded byisEmpty(), so it does not crash. A credit-only window there would release a PUBCOMP flush (and the seeded session stream) before Kafka acknowledged the commit. It needs the same position-based completion and its own failing script first.Generated by Claude Code