Repository navigation
fix(binding-mqtt-kafka): answer a filter that no route matches with a per-filter suback failure - #3231
Merged
jfallows merged 5 commits intoNov 14, 2026
Conversation
* feat(common-json): mark and rewind the generator A generator can mark its position between writes and rewind to it, which discards the bytes written since and restores the structural context, so a unit of output can be generated, measured and then kept or taken back and generated again. This is the output-side counterpart of the parser mark and rewind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ * refactor(common-json): require every generator to support mark and rewind The generator mark and rewind are declared without a default, as JsonGeneratorImpl is the one implementation of JsonGeneratorEx and supports both. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ * test(common-json): rewind the generator that escapes its output Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ --------- Co-authored-by: Claude <[email protected]>
…ter no route matches Failing scripts and ITs only, ahead of the production change for #3208: mqtt-kafka echoes the stored session state with reasonCode 0x80 on each filter no subscribe route matches, and the mqtt binding leaves such a filter out of its session state and skips it on resume. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ
…fter-failed-filter scenario The application scripts of subscribe.topic.filters.non.successful.unsubscribe are shared by the v4 and v5 ITs, and a v3.1.1 SUBSCRIBE always requests the retained messages to be sent, so the state they expect must carry the SEND_RETAINED flag in both versions. Adds the session state builder that sets the qos, flags and reason code of a filter together. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ
… per-filter suback failure The session factory marks each filter of the session state it echoes to the mqtt binding, on a SUBSCRIBE and when the stored state is delivered at CONNECT, with reason code 0x80 when no subscribe route authorized for the session matches it. The mqtt binding carries the code into the SUBACK, opens no subscribe stream for the filter, leaves it out of its session state and skips it on resume, so the connection stays open and the other filters of the SUBSCRIBE are delivered as usual. Nothing new is persisted. Fixes #3208 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ
This was referenced Nov 14, 2026
…ght-publish' into fix/3208-mqtt-kafka-unmatched-filter-suback # Conflicts: # runtime/binding-mqtt/src/test/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/server/v4/SubscribeIT.java # runtime/binding-mqtt/src/test/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/server/v5/SubscribeIT.java # specs/binding-mqtt.spec/src/test/java/io/aklivity/zilla/specs/binding/mqtt/streams/network/v4/SubscribeIT.java # specs/binding-mqtt.spec/src/test/java/io/aklivity/zilla/specs/binding/mqtt/streams/network/v5/SubscribeIT.java
jfallows
changed the base branch from
develop
to
fix/3220-mqtt-unsubscribe-in-flight-publish
November 14, 2026 21:23
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
MqttKafkaBindingConfig.resolveAllkeeps the mqtt-kafka routes that match any filter of a SUBSCRIBE, against a route table separate from the mqtt binding's. If no route matched any filter,MqttKafkaSubscribeFactoryrejected the stream and the server answered DISCONNECT 0x83 (onSubscribeReset). If only some filters matched, the unmatched ones were granted in the SUBACK and never delivered. The design is posted on #3208 (#3208 (comment)).What changed:
MqttTopicFilter.reasonCode = 0x80when no subscribe route authorized for the session matches the filter. This happens when the state is echoed after a SUBSCRIBE and when the stored state is delivered at CONNECT. Nothing new is persisted: the compacted sessions topic keeps the filter as the mqtt binding wrote it, and the code is recomputed from the current routes on every echo, so a code cannot outlive a route change. There is no distinction between "no route" and "no authorized route".MqttKafkaBindingConfig.resolveSubscribeReasonCodeand the existingresolveAllshare one predicate (subscribes), so the session and subscribe factories cannot disagree.reasonCodeis an existinguint8with default 0, so the rewritten state has the same size as the original and thereservedcredit of the DATA frame is unchanged. No IDL change.openSubscribeStreamsskips it. The SUBACK position and code of the failed filter come from the existingacknowledgedSubscriptions/doEncodeSubackpath.openSubscribeStreamsopens no stream, a SUBACK with a failure code per filter is encoded, and the connection stays open. The subscribe factory's reject and RESET for a stream with no matching route is unchanged.resolveSubscribeReasonCodereturn the same 0x80). MQTT 3.1.1 SUBACK failure is 0x80 as before.MqttBindingConfig.resolveSubscribeReasonCodeis not touched.Pattern mirrored: the mqtt binding's
doSendSessionState, which builds anMqttSessionStateFWwithsubscriptionsItemand a flyweight builder, for the state rewrite; andMqttBindingConfig.resolveSubscribeReasonCode(#3191) for the per-filter decision.MqttKafkaSessionFactorydid not rebuild the state payload before, so the rewrite is new in that module; the maintainer accepted this on #3208.Fixes #3208
Specification statements
I downloaded the OASIS MQTT 5.0 and 3.1.1 Standard pages, converted them to text and read these myself:
onSubscribeResetis not required.Not read: the rest of 5.0 section 3.9 beyond the code table rows above, and the full 3-8/3-9 tables. No clause says whether a failed subscription is part of the Session State; leaving it out of the stored state the mqtt binding writes is a reading, not a MUST.
Test evidence
Test-first: the first two commits hold only scripts, ITs and a session-state builder in
MqttFunctions; the third holds the production change. The second commit corrects a defect in my own first-commit script, not production behavior: the application scripts ofsubscribe.topic.filters.non.successful.unsubscribeare shared by v4 and v5, and a v3.1.1 SUBSCRIBE always sendsSEND_RETAINED, so the state they expect must carry that flag (the first commit failed v4 for that reason, not the intended one). This is whyMqttFunctionsgainedsubscriptionWithReasonCode(pattern, id, qos, reasonCode, flags...), covered inMqttFunctionsTest.shouldEncodeMqttSessionState.New scenarios (spec peer-to-peer ITs run in
NetworkIT/ApplicationIT-style classes, binding ITs against the engine):specs/binding-mqtt-kafka.spec:session.subscribe.unmatched.filter(one matching, one non-matching filter),session.subscribe.unmatched.all(no filter matches),session.subscribe.unmatched.resume(stored state delivered at CONNECT).MqttITandKafkaITpair each, andMqttKafkaSessionProxyITruns each against the engine withproxy.when.subscribe.topic.with.messages.yaml.specs/binding-mqtt.spec:subscribe.topic.filters.non.successful.unsubscribe(network v4 and v5, application): a failed filter echoed in the state is absent from the state written by the next UNSUBSCRIBE.session.subscribe.non.successful.resume(network v4 and v5, application, plus.session.expiry.neverfor v4): a stored filter carrying a failure code is not subscribed on resume.Red, against the unchanged production code, confirmed for the right reason (logs kept):
MqttKafkaSessionProxyIT.shouldSessionSubscribeUnmatchedFilter,shouldSessionSubscribeUnmatchedAll,shouldSessionSubscribeUnmatchedResume: the echoed state expectedsubscriptionWithReasonCode("other/one", 1, 128)and read[0x01 0x29 0x00 0x00 0x00 0x02 …]with reason code 0 (3 of 3 failed).SessionIT.shouldSessionSubscribeNonSuccessfulResume: the application stream sawMQTT_SUBSCRIBE_BEGIN_EX [clientId=client, qos=0, filters=array32<32, 2>], a subscribe stream for both filters instead of onlyreply.SubscribeIT.shouldSubscribeTopicFiltersNonSuccessfulUnsubscribe: the state after UNSUBSCRIBE read[0x01 0x17 0x00 0x00 0x00 0x01 0x00 0x00 0x00 …], one filter (sensor/two) left in the state, where an empty state was expected.binding-mqtt.spec, 6 inbinding-mqtt-kafka.spec).After the fix, each module
clean installwith checkstyle and license checks on, build cache skipped (-Dmaven.build.cache.skipCache=true), upstream modules installed beforehand, systemmvn(themvnwwrapper jar download returned 404 from Maven Central in this environment):specs/binding-mqtt.spec: 525 ITs, 0 failures, 2 skipped (+ 78 unit tests, 4 skipped)specs/binding-mqtt-kafka.spec: 285 ITs, 0 failures (+ 27 unit tests)runtime/binding-mqtt: 423 ITs, 0 failures, 6 skipped (+ 44 unit tests)runtime/binding-mqtt-kafka: 163 ITs, 0 failures (+ 10 unit tests)Not delivered
tryWrapon each DATA frame); a state split across frames is not handled.session.setSubscriptionsis called at one site only (the echo path after CONNECT), so the mqtt server may not populate its session subscriptions from the state delivered at resume. This is a reading of the code that was not tested, and this PR does not change it.🤖 Generated with Claude Code
https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ