Repository navigation
Conversation
…subscription
Add failing specs and ITs for a SUBSCRIBE whose Topic Filter is identical to an
existing Non-shared Subscription (MQTT 5.0 [MQTT-3.8.4-3], MQTT 3.1.1
[MQTT-3.8.4-3]): same QoS, same options and Subscription Identifier, QoS 2 to 0
downgrade, QoS 0 to 2 upgrade, and (v5) Subscription Identifier added, changed
and removed. Correct the two existing retain-handling existing-filter
application scripts, which asserted two session state entries for one filter
and so violated the replacement rule.
Against the current code the eleven scenarios below fail on the application
session stream: after the second SUBSCRIBE the server writes a session state with
two entries (the old entry and the new one) where one entry is expected (observed
bytes begin 0x01 0x2a 0x00 0x00 0x00 0x02 ..., length 0x2a, two items), so the
script does not match and then times out.
server.v5.SubscribeIT: shouldSubscribeReplaceSameQos,
shouldSubscribeReplaceSameOptions, shouldSubscribeReplaceDowngradeQos,
shouldSubscribeReplaceUpgradeQos, shouldSubscribeReplaceAddSubscriptionId,
shouldSubscribeReplaceRemoveSubscriptionId,
shouldSubscribeRetainHandling0ExistingFilter,
shouldSubscribeRetainHandling1ExistingFilter
server.v4.SubscribeIT: shouldSubscribeReplaceSameQos,
shouldSubscribeReplaceDowngradeQos, shouldSubscribeReplaceUpgradeQos
The scripts pass peer to peer in specs/binding-mqtt.spec.
Refs #3217
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXftpX2HBvgygJcdft
…ed again A SUBSCRIBE for a Topic Filter identical to an existing Non-shared Subscription now replaces it: the session state holds one entry per filter, the new QoS, options and Subscription Identifier take effect, the per-QoS-level subscribe streams drop the old entry (levels above the new QoS are flushed without it) and levels up to the new QoS carry the new entry. An identical re-subscribe, whose state entry equals the existing one, is still recognised as the new subscription and acknowledged. Frames already received on a level stream that loses its last entry are still dropped, as for UNSUBSCRIBE; see #3230. Fixes #3217 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoXftpX2HBvgygJcdft
…' into fix/3217-mqtt-resubscribe-replaces # 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/application/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/3218-mqtt-suback-granted-qos
November 14, 2026 21:28
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 SUBSCRIBE for a Topic Filter identical to an existing Non-shared Subscription added a second entry to the session state and to the per-QoS-level subscribe streams, so the old entry stayed live. A QoS 2 to 0 downgrade kept delivering at QoS 2 and the old Subscription Identifier persisted.
It now replaces the subscription, in
MqttServerFactory:replaceSubscriptionsbuilds the state with one entry per filter (a new successful entry replaces the existing one with the same filter), inonDecodeSubscribeV4/onDecodeSubscribeV5.openSubscribeStreamsfirst removes the old entry for the filter from every level stream of the route (MqttSubscribeStream.removeSubscriptions). Levels up to the new QoS then receive the new entry through the existing begin-or-flush path. Levels above it are flushed without the entry throughdoSubscribeFlushOrEnd.onSessionDatastill recognises it as the acknowledged new subscription, so the SUBACK is sent and the streams are flushed. Previously the equality check dropped it.SEND_RETAINEDflag.Pattern mirrored: the UNSUBSCRIBE path, which is already keyed by filter (
doSendSessionState,getSubscriptionByFilter,doSubscribeFlushOrEnd). The mqtt-kafka subscribe proxy already rebuilds its fetch filters from the full filter list in the flush, so it did not change. There is no IDL change.Fixes #3217
Specification statements
Read in the OASIS pages, quoted by sentence (clause numbers differ between the body text and the summary tables, so the body text is quoted):
MQTT 5.0, 3.8.4 (SUBSCRIBE Actions)
MQTT 5.0, 3.8.2.1.2 (Subscription Identifier)
MQTT 5.0, 3.8.3.1 (Subscription Options)
MQTT 3.1.1, 3.8.4 (Response)
Read: 5.0 3.8.4, 3.8.2.1.2 and 3.8.3.1; 3.1.1 3.8.4; 3.1.1 4.6 (message ordering, [MQTT-4.6.0-1] to [MQTT-4.6.0-6]) and the sentences of 3.1.1 4.3 on the QoS used for delivery. Not read: the body of 3.1.1 3.8.3 (only its Appendix B summary came back); 5.0 4.3 and 4.6 (they were not in the page text returned); the last 6,290 characters of the 5.0 page.
This change does not fully meet [MQTT-3.8.4-4] (5.0) or the "flow of publications MUST NOT be interrupted" sentence of [MQTT-3.8.4-3] (3.1.1). Frames already received on a level stream that loses its last entry (the QoS 2 to 0 case) are still dropped, as they are for UNSUBSCRIBE today. That is tracked in #3230. The entry replacement here is the part of [MQTT-3.8.4-3] and [MQTT-3.8.4-8] that does not depend on it: after the replacement, messages published are delivered at the new QoS, with the new identifier, once.
Test evidence
Commit 1 holds only scripts and ITs (new
.rptpairs and methods in the existingSubscribeITclasses, no new IT classes). The two existing application scriptssubscribe.retain.handling.0.existing.filterandsubscribe.retain.handling.1.existing.filterare corrected: they asserted two session state entries for one filter, which violates the replacement rule.Against the unchanged production code (
mvn -B clean verify -pl runtime/binding-mqtt -Dit.test=SubscribeIT), 11 runtime IT methods failed for the right reason: after the second SUBSCRIBE the server wrote a session state with two entries (observed bytes0x01 0x2a 0x00 0x00 0x00 0x02 ..., length 0x2a, two items) where one was expected, and the script then timed out withSpecified behavior did not match expected/TestTimedOutException:shouldSubscribeReplaceSameQos,shouldSubscribeReplaceSameOptions,shouldSubscribeReplaceDowngradeQos,shouldSubscribeReplaceUpgradeQos,shouldSubscribeReplaceAddSubscriptionId,shouldSubscribeReplaceRemoveSubscriptionId,shouldSubscribeRetainHandling0ExistingFilter,shouldSubscribeRetainHandling1ExistingFiltershouldSubscribeReplaceSameQos,shouldSubscribeReplaceDowngradeQos,shouldSubscribeReplaceUpgradeQosThe new scripts pass peer to peer in
specs/binding-mqtt.spec(ApplicationIT, v4 and v5SubscribeIT) before the fix.After the fix (commit 2), checkstyle, license and jacoco checks on, system
mvn:mvn -B clean verify -pl specs/binding-mqtt.spec,runtime/binding-mqtt: runtime module 44 unit tests, 428 ITs, 0 failures, 6 skipped. v5SubscribeIT71 and v4SubscribeIT44 all pass.mvn -B clean verify -pl specs/binding-mqtt.spec -Dmaven.build.cache.skipCache=true(the cache had restored this module in the combined run): 78 unit tests (4 skipped), 533 ITs, 0 failures, 2 skipped.-amfirst from the restoreddevelopbuild cache.Not run: the mqtt-kafka modules and the full reactor. No mqtt-kafka source or script changed. The new scripts were not run against a real MQTT client.
Not delivered
doSubscribeFlushOrEndcloses a stream that has not yet received its first window instead of flushing it, whatever filters remain. A level stream that only loses an entry goes through it, so this affects the window race of replace as well as UNSUBSCRIBE. It was left as it is.Generated by Claude Code