Repository navigation
Conversation
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoY9w3hMTTDhfpoWhLG
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoY9w3hMTTDhfpoWhLG
jfallows
force-pushed
the
fix/3166-mqtt-pending-ack-keys
branch
from
November 13, 2026 01:08
21bf269 to
4f75caa
Compare
This was referenced Nov 13, 2026
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
MqttServerFactorykept the pending QoS 1 and QoS 2 acknowledgements in two connection-levelLong2LongHashMaps (unAckedReceivedQos1PacketIds,unAckedReceivedQos2PacketIds), keyed by theinitialSeqof whichever publish stream carried the message. Each topic has its own publish stream with its own sequence, so the key is only meaningful inside one stream. The defect is real, and demonstrated by the failing scripts below:putoverwrote the first, and one stream's window acknowledgement then completed the other stream's entry. The first message's PUBACK was never sent.acknowledgePublishPacketsiterated the map in hash order,breaked at the first key above the acknowledgement, and removed entries while iterating.What changed:
MqttPublishStreamnow keeps its own pending acknowledgements: two parallel Agrona lists (pendingAckSequences,pendingAckPacketIds) in arrival order, plus the stream'sqos(a stream is already keyed per topic and qos bytopicKey).acknowledgePublishPacketsdrains the lists from the front while the head sequence is at or below the stream's own acknowledgement, so within one topic packets are acknowledged in the order received, nothing is skipped and nothing is removed while iterating.unreleasedPacketIds, which fix(binding-mqtt): answer an acknowledgement with an unknown packet id without failing #3179'sonDecodePubrelchecks.Long2LongHashMapimport are gone.Fixes #3166
This PR is based on #3179's branch (
fix/3165-mqtt-ack-unknown-packet-id, head56994b6ea), stacked on #3176 anddevelop. It will be retargeted as the lower PRs merge.Rebase onto #3179
Two rebases so far, both mechanical. The first onto
f41fb39dehad one import-line conflict. The second onto56994b6eahad no conflicts. The lower PRs changed the subscribe-side handlers (onDecodePuback,onDecodePubcomp,onDecodePubrec) andonDecodePubrel'sunreleasedPacketIdscheck, none of which this change touches. #3179's last two commits only add and drop test scenarios and change no production code. Its newrecovery.pubrel.unknown.packet.idscenario sends a QoS 2 PUBLISH (PUBREC goes through the per-stream lists and adds the id tounreleasedPacketIds), reconnects, then sends a PUBREL for an unknown id on the new connection, which starts with empty lists. It passes with this change.MQTT specification
I downloaded the full OASIS pages (
mqtt-v5.0-os.htmlandmqtt-v3.1.1-os.html), converted them to text and read these sections myself: v5.0 2.2.1, 4.2, 4.3.2, 4.3.3, 4.4, 4.5, 4.6; v3.1.1 2.3.1, 4.2, 4.3.2, 4.3.3, 4.4, 4.5, 4.6. Quotes below are from that text.What the specification requires of the receiver of a PUBLISH, which is what this change is anchored to:
What the specification says about acknowledgement order (4.6 "Message ordering"):
publish.qos1.two.topics.interleaved.acksexpects PUBACK 2 before PUBACK 1 because the application acknowledgedsensor/twofirst and each topic's stream is acknowledged independently. That order is a choice of this implementation, not something the specification demands or forbids for a Server. The same-topic script expects PUBACK 1 then PUBACK 2, which is the order of arrival; the specification does not demand it of a Server either, though the Client rule above is the same shape.Not read: v5 2.4 reason code table, 3.4 to 3.7 packet sections, 4.9 flow control, 4.12. I did not check other brokers.
Test evidence
Test-first: the first commit (
ebc963842) holds scripts and IT methods only.Scripts added (client and server pair each), with IT methods in the existing
PublishITclasses (spec network v4 and v5, spec application, runtime server v4 and v5), no new IT class:publish.qos1.two.topics.interleaved.acks(network v4, v5; application): two QoS 1 publishes onsensor/one(packet id 1) andsensor/two(packet id 2). The application side holds acknowledgements back (option zilla:update "handshake"andread option zilla:ack) and acknowledgessensor/twofirst. Expected PUBACK 2 then PUBACK 1.publish.qos1.two.messages.one.ack(network v4, v5; application): two QoS 1 messages on one topic acknowledged by a single window advance (read option zilla:ack 14). Expected PUBACK 1 then PUBACK 2.What failed first, against the unchanged production code of the base (
56994b6ea, test commit only):shouldPublishQoS1MessagesToTwoTopicsWithInterleavedAcksfailed in runtime v4 and v5: PUBACK 2 arrived and PUBACK 1 was never sent, then the test timed out.shouldPublishTwoQoS1MessagesAcknowledgedTogetherfailed in runtime v4 and v5 with a script mismatch on the PUBACK. I did not dig into whether the cause was order or a missing PUBACK, so the hash-order claim is not independently confirmed; I only know the unchanged code fails this scenario and the fixed code passes it.developatb1a53e98fand failed there the same way before the rebase.shouldPublishSubscribeBatched, v5) appeared once on an early base-only run and did not appear in any later run, including this base. I did not investigate it, so I cannot say whether it is a flake.After the fix, final verification on head
4f75caa34:clean installwith checkstyle, license and coverage checks on, build cache disabled (-Dmaven.build.cache.skipCache=true), overspecs/binding-mqtt.specandruntime/binding-mqtt. Upstream modules were installed earlier fromdevelop; the mqtt-kafka modules are not touched by this change and were not run. BUILD SUCCESS, 0 failures, 0 errors:specs/binding-mqtt.spec: 487 ITs (2 skipped) + 75 unit and schema tests (4 skipped)runtime/binding-mqtt: 401 ITs (6 skipped) + 44 unit testsI ran this once on the final head, so I have no flake data.
CI: the checks that run on this PR are reported by the PR's check runs, not by this description.
Not delivered / follow-ups
unreleasedPacketIds) uses the same per-stream lists and is covered by the existing QoS 2 ITs and fix(binding-mqtt): answer an acknowledgement with an unknown packet id without failing #3179's recovery scenario, which pass, but there is no new test that fails without the change.message, no padding), so the acknowledgement values 7 and 14 depend on that.mqttPublishHelperis a single factory-level object shared by all connections' decoders; this change no longer reads itsqosfor acknowledgement, but I did not audit its other uses.🤖 Generated with Claude Code
https://claude.ai/code/session_01SiHVoY9w3hMTTDhfpoWhLG