Repository navigation
fix(binding-mqtt-kafka): keep subscribe offset bookkeeping per client and per stream - #3180
Merged
jfallows merged 4 commits intoNov 13, 2026
Conversation
… while an offset commit is deferred Client one receives a QoS 2 message at offset 2 and a QoS 1 message at offset 3, and sends the PUBACK for the QoS 1 message first. That is conforming, because MQTT-4.6.0-2 and MQTT-4.6.0-3 order PUBACKs and PUBRECs only among themselves. The offset commit for offset 3 is deferred until offset 2 is acknowledged. Client two then begins a subscription on the same topic and partition, and client one sends the PUBREC for the QoS 2 message. Both offset commits are expected to reach Kafka for client one. Currently the deferred commit is never sent. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUEKMNLJThWJnkEvpG
…packet id Two clients each restore packet id 1 from offset metadata, with different offsets. Each client's acknowledgement of packet id 1 is expected to commit its own offset. Currently the second client's restore replaces the first client's offset and the second acknowledgement finds no offset. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUEKMNLJThWJnkEvpG
The subscribe factory kept one high-water mark per topic partition for every client on the worker. A second client beginning a subscription replaced the mark of the first client and dropped its deferred offset commits, so those commits were never sent to Kafka. The marks are now shared only by the streams of one client and released with the client's last stream. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUEKMNLJThWJnkEvpG
Packet ids restored from offset metadata are scoped to one client, but were stored in a map shared by every client on the worker. Two clients restoring the same packet id replaced each other's offset, so one acknowledgement committed the wrong offset and the next found none. Offsets are now kept by the subscribe stream that delivers or restores the packet id and receives its acknowledgement. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUEKMNLJThWJnkEvpG
jfallows
changed the base branch from
develop
to
fix/3177-mqtt-per-filter-suback-failure
November 13, 2026 01:39
jfallows
force-pushed
the
fix/3167-mqtt-kafka-subscribe-offset-maps
branch
from
November 13, 2026 01:40
747ecdc to
ad8f8df
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
MqttKafkaSubscribeFactorykept two maps that every client on an engine worker shared. Two clients on one worker interfered with each other's acknowledgement state. The suspicion in #3167 came from reading the code; both findings below are demonstrated by failing tests.1. High-water marks (
highWaterMarks)One mark per topic partition was shared by every client. When a second client began a subscription, its Kafka begin replaced the first client's mark with a new empty one. Offset commits the first client had deferred were dropped and never sent to Kafka. A commit is deferred when an acknowledgement for a later offset arrives while an earlier offset is still unacknowledged.
The marks are now kept per client: a
ClientHighWaterMarksentry keyed by client id, shared by that client's QoS 0, 1 and 2 streams, and removed when the client's last subscribe stream closes. They must stay shared across a client's streams, because the QoS 0 stream advances the mark past offsets the QoS 1 and 2 streams never receive (shouldReceiveMessagesMixtureQoscovers this). My first attempt scoped them to one stream and broke that test.2. Packet id offsets (
offsetsPerPacketId)Counter-assigned packet ids are unique per worker, but ids restored from offset metadata on reconnect are only unique within one client. Two clients restoring the same packet id replaced each other's offset. The first acknowledgement removed the entry the second client had restored, and the second acknowledgement threw
NullPointerException: Cannot read field "topicKey" because "offset" is nullinonMessageAcked, which terminates the engine worker.The offsets are now kept by the
MqttSubscribeProxythat delivers or restores the packet id and receives its acknowledgement.Fixes #3167
This PR is stacked on #3191's branch (
fix/3177-mqtt-per-filter-suback-failure,3fd498c5), the tip of the mqtt binding PRs, which sits ondevelop. It will be retargeted todevelopafter the PRs below it merge. The stack below it changesMqttKafkaPublishFactory,MqttKafkaSessionFactory, the mqtt server and the spec ITs, notMqttKafkaSubscribeFactory, so the restack onto it was mechanical: no conflicts, and no changes beyond the cherry-picks.MQTT specification statements
I read these in the full OASIS texts (MQTT v5.0 OS and v3.1.1 OS, downloaded and read as text), not from a summary.
What the fixes serve:
Where the specification is silent:
Test evidence
Test-first: the first two commits hold the scripts and IT methods only. Run against the unchanged production code on this base (
3fd498c5), each scenario fails:shouldKeepPendingOffsetCommitWhenSecondClientBeginsSubscribe: everything up to the early PUBACK and the later PUBREC matches, and the deferred commitprogress(0, 4)never reaches Kafka (the test times out).shouldKeepPacketIdOffsetWhenSecondClientRestoresQoS2: the engine worker terminates with theNullPointerExceptionabove.The spec peer-to-peer ITs (
MqttIT,KafkaIT) pass for both scenarios, so each script pair agrees with itself.After the fix,
clean verifywith checkstyle and license checks on, build cache skipped (-Dmaven.build.cache.skipCache=true), upstream modules installed with-am:specs/binding-mqtt-kafka.spec: 264 ITs (MqttIT119,KafkaIT145), 0 failures, plus 27 unit testsruntime/binding-mqtt-kafka: 150 ITs (MqttKafkaSubscribeProxyIT67,MqttKafkaSessionProxyIT38,MqttKafkaPublishProxyIT45), 0 failures, plus 10 unit testsMqttKafkaSubscribeProxyIT.shouldReceiveServerSentRetainedReset(the known intermittent failure from #3161) did not fail in this run.An install of the whole upstream reactor with notice checks on fails in the untouched
buildmodule (managerandzpm-maven-pluginsnapshot licenses unresolved), so the upstream modules were installed with-Dskip.checks=true. The two touched modules were verified with all checks on.Scripts added (both sides):
subscribe.mixed.qos.second.client.begin.keeps.pending.offset.commit(mqtt/andkafka/): one client has a QoS 2 stream and a QoS 1 stream. It receives the QoS 2 message at offset 2 and the QoS 1 message at offset 3, and sends the PUBACK for the QoS 1 message first, which defers that offset commit. A second client then subscribes. The first client sends the PUBREC for the QoS 2 message, receives the PUBREL and sends the PUBCOMP. Both offset commits are expected to reach Kafka for the first client.subscribe.qos2.second.client.restore.keeps.packet.id.offset(mqtt/andkafka/): two clients each restore packet id 1 with different offsets and acknowledge it.Not delivered
putas before). That is the same-client case and was not demonstrated as a defect here.packetIdCounteris still per worker; it is not client state, and no interference was found there.Follow-ups