Repository navigation
fix(binding-mqtt): send PUBACK and PUBREC in publish receive order - #3106
Merged
Merged
Conversation
6 tasks done
Pending QoS 1 and QoS 2 packet ids were tracked in hash maps keyed by the publish stream's own sequence, so acknowledgements were emitted in hash iteration order, collided across streams with equal sequences, and could be skipped by the early break. Track them in an ordered per-connection queue and acknowledge from the head only once its stream has been acknowledged ([MQTT-4.6.0-2]). Fixes #3102 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVggtnCBMjAczLoou4
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVggtnCBMjAczLoou4
…erleaved acks Correct four scenarios that acknowledged across two topics out of receive order, which violates [MQTT-4.6.0-2] and [MQTT-4.6.0-3] (a Server MUST send PUBACK and PUBREC packets in the order the PUBLISH packets were received). Each expected the acknowledgement of packet id 2 before packet id 1: network/v4/publish.qos1.two.topics.interleaved.acks network/v4/publish.qos2.two.topics.interleaved.acks network/v5/publish.qos1.two.topics.interleaved.acks network/v5/publish.qos2.two.topics.interleaved.acks Only the order of the two acknowledgements changes, in each client.rpt and server.rpt; the application scripts still acknowledge sensor/two first. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVggtnCBMjAczLoou4
jfallows
force-pushed
the
fix/3102-mqtt-puback-order
branch
from
November 17, 2026 01:17
7345d4e to
badddc6
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
Pipelined QoS 1 PUBLISH packets were acknowledged out of order, violating MQTT 5.0 [MQTT-4.6.0-2];
mosquitto_pub -lexits early and loses messages.Root cause.
MqttServerFactorykept pending QoS 1 / QoS 2 packet ids in twoLong2LongHashMaps keyed by the publish stream's owninitialSeq, then iterated them on each application window update:breakon the first key above the acknowledge could leave acknowledgements unsent.Reordering originates in the
mqttserver, not in themqtt-kafkaproduce path.Fix. Each publish stream keeps its pending (sequence, packet id) pairs in a
LongArrayQueue, and the connection keeps anArrayDequeof the streams in publish receive order (mirroring the ordered stream queue inKafkaCacheClientConsumerFactory). Acknowledgements are emitted from the head only while the head's stream has been acknowledged, so PUBACK (QoS 1) and PUBREC (QoS 2) follow PUBLISH order across topics. PUBCOMP already follows PUBREL order since it is sent on receipt.Tests (test-first).
publish.pipelined.qos1.ack.out.of.order(application + network v4/v5), where the application acknowledges the second publish before the first, with peer-to-peerPublishITmethods.PublishIT.shouldPublishPipelinedQos1AckOutOfOrder(v4, v5): fails on the old code (Specified behavior did not match expectedon PUBACK), passes with the fix../mvnw clean install -pl specs/binding-mqtt.spec,runtime/binding-mqtt(checkstyle, all ITs, coverage) passes.examples/mqtt.kafka.proxy, raw MQTT 5 client sending N back-to-back QoS 1 PUBLISH): before, 5 messages on one topic acked[5, 3, 1, 2, 4], 200 messages fully shuffled, and with 3 topics some acks were missing; after, 5 and 200 messages on 1 and 3 topics are acked in order.Fixes #3102
Generated by Claude Code