Repository navigation
fix(binding-mqtt): end the qos 2 flow on a pubrec failure reason code - #3176
Merged
Merged
Conversation
… reason codes Adds mqtt v5 network and application scripts and IT methods for a QoS 2 PUBLISH answered with PUBREC reason codes 0x80 and 0x97 followed by a successful message, and a QoS 1 PUBLISH answered with PUBACK 0x80 followed by a successful message (MQTT 5.0 sections 3.4.2.1, 3.5.2.1 and 4.3.3). The QoS 2 runtime IT fails against the current code. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVLaAwrBN1PSG42tFv
A PUBREC with a reason code of 0x80 or above completes the QoS 2 exchange without a PUBREL (MQTT 5.0 section 4.3.3). Complete the message downstream as for a PUBCOMP instead of persisting it as INCOMPLETE and waiting for a PUBCOMP that never arrives. MQTT 3.1.1 PUBREC handling is unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVLaAwrBN1PSG42tFv
jfallows
force-pushed
the
fix/3164-mqtt-ack-failure-reason-codes
branch
from
November 12, 2026 23:55
f5ac278 to
46ec36c
Compare
jfallows
changed the base branch from
fix/3158-mqtt-kafka-retained-topic-compaction
to
develop
November 12, 2026 23:56
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
A PUBREC from an MQTT 5.0 client with a reason code of 0x80 or above was handled like a successful PUBREC.
MqttServerFactory.onDecodePubrecignored the reason code and always flushedstate=INCOMPLETEto the application stream. With mqtt-kafka that is acked, the server sends a PUBREL, and the stream waits for a PUBCOMP the client will never send.What changed:
decodePubrecV5reads the PUBREC reason code (an omitted reason code, remaining length 2, is success, per 3.5.2.1) and passes it toonDecodePubrec.onDecodePubreccompletes the message the wayonDecodePubcompdoes: the packet id is removed fromqos2Subscribes, the window is granted and a COMPLETE flush goes to the application. No PUBREL is sent and no INCOMPLETE state is persisted. This mirrors the existing PUBCOMP path; there is no new flag and no IDL change, and the decision stays in the MQTT server, which already owned it.decodePubrecV4passes success, so MQTT 3.1.1 behavior is unchanged.Fixes #3164
This PR is based on
develop(5556779, which includes #3159 to #3162). It was rebased onto it from the #3162 branch with no conflicts and nothing changed beyond the mechanical rebase.Spec statements
Zilla is the sender of the PUBLISH to a subscriber here, and the client is the receiver that sends the PUBREC or PUBACK. All quotes are from the OASIS text, which I downloaded in full and read as text (MQTT 5.0 os: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html; MQTT 3.1.1 os: https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html). Clause ids are as they appear.
MQTT 5.0:
How they map to the change:
[MQTT-4.3.3-9] (a later PUBLISH with that packet identifier is a new Application Message after the receiver has sent a PUBREC of 0x80 or above) is a receiver rule, so it does not apply to this change, where the server is the sender. An earlier version of this description cited it for the sender; that was wrong.
MQTT 3.1.1 (4.3.3 and 4.4): the PUBREC has only the Packet Identifier in its variable header and no payload (3.5.2, 3.5.3), so there is no reason code. The sender "MUST send a PUBREL packet when it receives a PUBREC packet from the receiver" with no qualification, and the identifier "becomes available for reuse once the Sender has received the PUBCOMP Packet". 4.4 requires resending unacknowledged PUBLISH and PUBREL packets only when a client reconnects with CleanSession 0. The 3.1.1 text has no equivalent of [MQTT-4.4.0-2], so the 3.1.1 path is unchanged: every PUBREC is a success PUBREC.
Test evidence
Test-first: the first commit holds the scripts and IT methods only. Against the unchanged production code (that commit alone, on
develop5556779), the new runtimeSubscribeIT.shouldReceiveMessageQoS2AfterPubrecFailureReasonCodesfailed (the server flushed INCOMPLETE where the script expects a plain flush; the retry timed out).shouldReceiveMessageQoS1AfterPubackFailureReasonCodepassed, as expected. The spec peer-to-peer ITs for both scripts passed (network v5, network v4 and applicationSubscribeIT, 130 tests), so the scripts agree with each other.After the fix, on this branch on
develop5556779,clean verifywith checkstyle and license checks on, build cache skipped (-Dmaven.build.cache.skipCache=true), upstream modules installed with-am:specs/binding-mqtt.spec: 469 ITs, 0 failures, 2 skipped (+ 75 unit and schema tests, 4 skipped)runtime/binding-mqtt: 386 ITs, 0 failures, 6 skipped (+ 44 unit tests)The mqtt-kafka modules are not touched and were not run.
Scripts added (network v5 and application, client and server each):
subscribe.receive.message.qos2.pubrec.failure.reason.codes: PUBREC 0x80 and PUBREC 0x97 each end the flow with no PUBREL, and a third message then completes the normal PUBREC, PUBREL, PUBCOMP exchange on the same stream.subscribe.receive.message.qos1.puback.failure.reason.code: PUBACK 0x80, then a second message is delivered and acknowledged.CI: no check runs had been reported for this head when this was written; the local runs above are the evidence until they are.
Not delivered
MqttEventType) only hasCLIENT_CONNECTED, so no existing event fits and I did not add a new event type, as the issue asks to raise that first.onDecodePubrecandonDecodePubackdereference theqos2Subscribesorqos1Subscribeslookup without a null check, as the success paths already did. I did not change this.Follow-ups
🤖 Generated with Claude Code
https://claude.ai/code/session_01SiHVoVLaAwrBN1PSG42tFv