Repository navigation
Description
Problem
MqttKafkaBindingConfig.resolveAll keeps the routes that match any filter of a SUBSCRIBE, against a route table separate from the mqtt binding's. Read on develop, not run as a failing scenario:
- If no route matches any filter of the SUBSCRIBE,
MqttKafkaSubscribeFactoryrejects the stream and the server answers DISCONNECT 0x83 (onSubscribeReset), closing a connection that may carry other in-flight packets. - If only some filters match, the unmatched ones are granted in the SUBACK but never delivered.
The mqtt binding already answers a filter that its own routes cannot resolve with a per-filter SUBACK failure and leaves it out of the session state. A filter that only the mqtt-kafka route table fails to match gets neither.
Related: a failure code set by the application peer on a filter in the echoed session state (MqttTopicFilter.reasonCode) is carried into the SUBACK, but the filter itself stays in the stored session state. Nothing sets such a code today; this change would.
Expected
- A filter that no mqtt-kafka route matches is answered with the same per-filter failure code as a filter that no route matches in the mqtt binding (0x83 on MQTT 5, 0x80 on MQTT 3.1.1), with no distinction between "no route" and "no authorized route".
- The other filters of the SUBSCRIBE are granted and delivered as usual.
- A SUBSCRIBE in which no filter matches gets a SUBACK with a failure code per filter and the connection stays open.
- A failed filter is not left in the session state.
Design first
Before any code, post a short design on this issue: where the failure is decided and how it reaches the SUBACK (the existing reasonCode on the filter in the session state and application protocol, which component sets it and which persists it in the compacted sessions topic), what happens to the session state when a failed filter is echoed back, how a whole-SUBSCRIBE mismatch flows through the subscribe stream, and what changes in the mqtt-kafka session and subscribe factories. The pattern to mirror must be an existing implementation in the same modules; if none fits, or an IDL change is needed, say so and ask.
Test plan (test-first)
After the design is accepted: scripts for v5 and v4 in specs/binding-mqtt-kafka.spec (and specs/binding-mqtt.spec if the application protocol changes) for a SUBSCRIBE with one matching and one non-matching filter, a SUBSCRIBE with no matching filter, and a failed filter absent from the stored state on resume. The first commit holds the failing scripts.
Notes
Follow-up to the per-filter SUBACK failure change under #3177. Part of the MQTT conformance work under #512.
Activity
jfallows commentedon Nov 13, 2026
Design
Update: the per-filter code is 0x80 (Unspecified error) on MQTT 5 and on MQTT 3.1.1 (the maintainer's decision, same value as the mqtt binding in #3223); the earlier text of this comment said 0x83 on MQTT 5. The three checks listed as unverified are done (results below), and the read side was chosen. The implementation is in #3231.
Policy as given: no distinction between "no route" and "no authorized route". A filter that no mqtt-kafka SUBSCRIBE route matches gets the same per-filter code as an unroutable filter in the mqtt binding: 0x80 on MQTT 5 and on MQTT 3.1.1.
What I read on
developMqttServerFactory): per-filter failure travels onSubscription.reasonCode.openSubscribeStreamsskips filters whose code is not SUCCESS, encodes the SUBACK from the list, and drops failed filters from the subscribe streams.MqttBindingConfig.resolveSubscribeReasonCodeis the decision in the mqtt binding (fix(binding-mqtt): answer an unroutable filter with a per-filter suback failure #3191). When the session replies with state, the echoed filters are read withsubscription.reasonCode = filter.reasonCode()and handed toopenSubscribeStreamsthroughacknowledgedSubscriptions.session.setSubscriptions(newState)stores every echoed filter, including one whose code is a failure. This is the gap the issue describes, and it only becomes reachable once something sets a code.filter.reasonCode()beforeopenSubscribeStreams(…, implicitSubscribe=true), so it must carry the code for a marked filter to be skipped there too. This is an extra finding beyond the first draft of the design.onMqttStateDataforwards the state payload to the compacted sessions topic unchanged.KafkaSessionStateProxy.onKafkaDataImplwraps the fetched value asMqttSessionStateFWand echoes it withdoMqttData. It never readssubscriptions()orreasonCode.MqttKafkaBindingConfig.resolveAll.resolveAllreturns routes that match any filter, so a per-filter answer is lost. It cannot return a per-filter code on the request direction: a null route list becomes a RESET, which the mqtt server turns into DISCONNECT 0x83 (onSubscribeReset).Where the failure is decided
In the mqtt-kafka session factory, at the point the state reaches the mqtt binding. A reply-side per-filter signal on the subscribe stream would need an IDL change. The session state already carries
MqttTopicFilter.reasonCode, and the SUBACK is built from it, so no IDL change is needed.MqttKafkaBindingConfig.resolveSubscribeReasonCode(authorization, filter)returns SUCCESS when a route authorized for the session matches the filter underMqttKafkaConditionKind.SUBSCRIBE, otherwise 0x80 (a constant of the mqtt-kafka binding). It mirrorsMqttBindingConfig.resolveSubscribeReasonCodeminus the 0x87 branch, which the policy removes.resolveAlland the new method share the same matching predicate, so the subscribe factory and the session factory cannot disagree.reasonCode = 0x80on each filter of the echoed state for which that method returns non-SUCCESS, and forwards the rest unchanged.reasonCodeis an existinguint8field with a default of 0, so the rewritten payload keeps its size and the credit accounting (reserved, window) is unaffected.Decided (maintainer): read side. The state is annotated when it is echoed to the mqtt binding (
onKafkaDataImpl), not when it is written. The compacted topic keeps the filter exactly as the mqtt binding wrote it and no code is ever persisted. The annotation is recomputed from the current routes on every echo and on every resume, so a stale code cannot outlive a route change. The same code path covers the live SUBSCRIBE echo and the state delivered at CONNECT. Neither choice needed an IDL change.No existing implementation in the module to mirror.
MqttKafkaSessionFactoryhas no code that rebuilds the state payload. The closest implementations are the mqtt binding'sdoSendSessionState, which builds anMqttSessionStateFWwithsubscriptionsItemand a flyweight builder, andresolveSubscribeReasonCodefor the decision. The read-side rewrite is new in this module; the maintainer accepted that.What happens to a failed filter echoed back (mqtt binding change)
On the echo path,
session.setSubscriptions(...)keeps only filters withreasonCode == SUCCESS(the same skip #3191 applies when it builds the state). The failed filter's SUBACK position is kept because the SUBACK is encoded from the packet'sunAckedSubscriptions/acknowledgedSubscriptionslist, as today. On resume the code of a stored filter is carried, soopenSubscribeStreamsskips it.session.subscriptions(), so it omits the failed filter and the topic is rewritten.Whole-SUBSCRIBE mismatch
It never reaches the subscribe stream. When every filter is annotated,
openSubscribeStreamsopens no subscribe stream and encodes a SUBACK with a failure code per filter; the connection stays open. For a partial match, only the matching filters reach the subscribe factory, so "granted but never delivered" cannot occur.MqttKafkaBindingConfig(the shared resolution),MqttKafkaSessionFactory(annotate the echoed state),MqttServerFactory(skip failed filters when storing the echoed state, carry the code on resume).MqttKafkaSubscribeFactoryis not changed.Statements anchored in the specification
I downloaded the OASIS MQTT 5.0 and 3.1.1 Standard pages, converted them to text and read these myself:
onSubscribeReset.Not read: the rest of 5.0 section 3.9 beyond the code row above, and the full tables 3-8 and 3-9. No clause says whether a failed subscription is part of the session state; leaving it out is a reading, not a MUST.
The three checks
tryWrapon each session DATA frame without reassembly, so the whole state must already arrive in one frame; the rewrite adds no new constraint.sessionId, and both route checks use it.Subscriptionequality.equalsincludesreasonCode, so a failed filter, never stored insession.subscriptions(), is seen as new once and acknowledged with its echoed code.Test plan
Test-first; implemented in #3231.
specs/binding-mqtt-kafka.spec(mqtt and kafka streams, no network side): one matching and one non-matching filter, no matching filter, and a stored non-matching filter delivered at CONNECT, each with the state echoed withreasonCode0x80 on the non-matching filter.specs/binding-mqtt.spec: network v4 and v5 plus application scripts for a failed filter that is absent from the state the binding writes next (UNSUBSCRIBE), and a stored filter carrying a failure code that is skipped on resume. No IDL change, so the application protocol is not touched.Generated by Claude Code
fix(binding-mqtt-kafka): answer a filter that no route matches with a…
fix(binding-mqtt-kafka): answer a filter that no route matches with a…
test(binding-mqtt): rename subscribe.reject.missing.packet.id to omit…