Repository navigation
feat(binding-mqtt): answer a failed mqtt 5 publish with a failure PUBACK or PUBREC - #3190
Merged
jfallows merged 4 commits intoNov 13, 2026
Conversation
… on a failed mqtt 5 publish Add the mqtt publish flush extension (packetId, reasonCode) to the application protocol with its builder and matcher, and the v5 scripts and IT methods for an unroutable publish, a rejected message, a QoS 2 rejected message and a rejected message with another QoS 1 message in flight, plus the v3.1.1 script where a rejected message still closes the connection. Against the unchanged runtime these fail: the server closes the connection with DISCONNECT, or acknowledges with reason code 0x00. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVMP35CVUCUo9s4vpd
…gement when kafka resets a qos 1 publish Add the mqtt and kafka scripts and IT methods for a Kafka reset that fails the unacknowledged QoS 1 messages of a publish stream with the mapped reason code while the mqtt stream stays open and the Kafka stream is replaced: one message, two messages in flight, a message already acknowledged by Kafka that keeps its success acknowledgement, and a record too large mapped to packet too large. Against the unchanged runtime the mqtt stream is aborted instead. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVMP35CVUCUo9s4vpd
…nowledgement Answer an unroutable QoS 1 or QoS 2 publish with PUBACK or PUBREC 0x87 and skip its payload, and apply a per-message failure reported by the application on the publish stream to the PUBACK or PUBREC of that packet without closing the connection. A rejected QoS 2 packet id is reusable. MQTT 3.1.1 still closes the connection. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVMP35CVUCUo9s4vpd
… kafka resets a publish stream When Kafka resets the messages or the retained stream of a QoS 1 publish after it opened, report the messages Kafka has not yet acknowledged to the mqtt binding as failed, with reason code 0x97 for a record that is too large and 0x83 otherwise, replace the Kafka stream, and fail the messages that arrive meanwhile. The mqtt stream stays open. QoS 0 and QoS 2 keep resetting the stream. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVMP35CVUCUo9s4vpd
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
On MQTT 5 a PUBLISH that fails no longer closes the connection. A QoS 1 publish gets a PUBACK and a QoS 2 publish gets a PUBREC with a failure reason code, and the connection and the other packets in flight stay as they are. MQTT 3.1.1 is unchanged and still closes the connection. QoS 0 is unchanged.
Design and spec check: design comment and spec check comment.
What changes
Application protocol (
mqtt.idl, shared).MqttFlushExgainscase 0: MqttPublishFlushEx { uint16 packetId; uint8 reasonCode }(the unused slot forMqttExtensionKind.PUBLISH), sent on the reply direction of a publish stream, with a builder and matcher inMqttFunctions. Justification in the protocol's own terms: today a publish stream can report success only cumulatively, through the WINDOW acknowledge, or end. There is no way to fail one message and leave the stream and its other messages alone, although MQTT 5.0 4.13.2 defines the failed acknowledgement as having "no consequences for other Sessions or other Packets flowing on the same Session". The contract: a message the receiving side cannot accept is reported by a FLUSH carrying itspacketIdand a reason code of 0x80 or greater; the stream stays open; the sender still acknowledges the message's bytes, so credit is returned exactly as for a successful message.binding-mqtt (QoS 1 and 2)
MqttPublishFlushExon a publish stream sets the reason code recorded for that packet in the per-stream pending list added by fix(binding-mqtt): key pending acknowledgements per publish stream #3186; the PUBACK or PUBREC carries it when the stream's cumulative acknowledge reaches the packet. A failed QoS 2 packet id is not added tounreleasedPacketIds.binding-mqtt-kafka (QoS 1)
KafkaResetExhas only the error), so every message not yet acknowledged on that stream fails with the same code. Attribution to one record is a binding-kafka capability gap, tracked in binding-kafka: a failed produce stream reset does not identify the record that failed #3178.Decisions to review
MQTT statements checked
Read in the OASIS texts (MQTT 5.0 os and MQTT 3.1.1 os), clause ids as they appear:
For MQTT 5.0 nothing in the text requires a particular response to a QoS 0 publish a server cannot accept; closing with DISCONNECT (0x83, 0x87, 0x95, 0x97 are all listed) is allowed and is what happens today.
Every statement above was read by me in the OASIS texts; the reason code table on #3171 was not used as a source for any of them.
Test evidence
This PR is stacked on #3186 (head
4f75caa34). Test-first, in this order:test(binding-mqtt),test(binding-mqtt-kafka),feat(binding-mqtt),feat(binding-mqtt-kafka).Failed first, against the unchanged production code (checked on this base, at the second test commit):
publish.qos1.unroutable,publish.qos2.unroutable(DISCONNECT instead of PUBACK or PUBREC 0x87),publish.qos1.message.rejected,publish.qos2.message.rejected,publish.qos1.message.rejected.in.flight.acknowledged(PUBACK or PUBREC 0x00 instead of 0x83), andpublish.qos1.message.rejected.close.connection(v3.1.1: the connection stays open).publish.qos1.server.sent.reset,publish.qos1.server.sent.reset.in.flight,publish.qos1.server.sent.reset.after.acknowledged,publish.qos1.reject.large.message,publish.qos1.retained.server.sent.reset(the mqtt stream is aborted instead of the failure flush and a replacement Kafka stream).NetworkIT,ApplicationIT,MqttIT,KafkaIT) andMqttFunctionsTestpass in the test commits.After the
feat(binding-mqtt)commit (the intermediate state): all binding-mqtt scenarios pass; ofMqttKafkaPublishProxyIT(50 tests) only the 5 new scenarios fail, as expected, because they needfeat(binding-mqtt-kafka).After both feat commits,
clean verifywith checkstyle, license and notice checks on and the build cache skipped:0 failures, 0 errors.
MqttKafkaSubscribeProxyIT.shouldReceiveServerSentRetainedResetdid not flake in this run.Observations to review
publish.qos1.message.rejected.in.flight.acknowledgedwas red on develop because PUBACK for packet 2 was sent before packet 1; it is green on the base of this PR (fix(binding-mqtt): key pending acknowledgements per publish stream #3186). I did not isolate why, and do not claim the cause.buildmodule fails its notice check when built from source in a fresh environment, unrelated to this change, so the upstream modules were installed without checks and the four modules above were verified with checks on.Not delivered / follow-ups
onMqttDatawrites the INCOMPLETE offsets record (doCommitOffsetIncomplete) at the message's FIN, before Kafka acknowledges the produce, and records the packet id in the client's shared offset metadata (packetIds,partitions) that the session factory also uses. Failing a QoS 2 message needs a compensating commit and a rollback of that shared state, which is a design question for the exactly-once recovery state, not a mapping. So a v5 QoS 2 failure PUBREC exists in binding-mqtt (reported by the application with the flush) but binding-mqtt-kafka does not send it yet: a Kafka reset on a QoS 2 publish still resets the mqtt stream, and the connection ends as before.Fixes #3175
Generated by Claude Code