Repository navigation
fix(binding-mqtt): complete in-flight shared deliveries before the unsubscribe state write - #3157
Merged
jfallows merged 13 commits intoNov 17, 2026
Conversation
This was referenced Nov 12, 2026
Closed
jfallows
force-pushed
the
feature/mqtt-shared-subscriptions-11-unsubscribe-drain-recovery
branch
from
November 12, 2026 21:45
a14002d to
6783a8f
Compare
jfallows
force-pushed
the
feature/mqtt-shared-subscriptions-11-unsubscribe-drain-recovery
branch
from
November 17, 2026 08:34
6783a8f to
28d1b73
Compare
… after the drain An UNSUBSCRIBE of a shared subscription with in-flight QoS 1 or 2 deliveries stops new messages, then writes the session state without the subscription and sends UNSUBACK only once the in-flight acknowledgements complete. A disconnect before then leaves the subscription in the session state. Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
… in-flight deliveries complete An UNSUBSCRIBE of a shared subscription with in-flight QoS 1 or 2 deliveries now stops new messages at once but keeps the subscription in the session state until the in-flight acknowledgements complete, then writes the state and sends UNSUBACK. A client that disconnects mid-drain keeps the subscription in the state, so it is restored on reconnect and unfinished deliveries can be completed. Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…scribe drains While an unsubscribed shared stream drains, new messages are dropped, an application reset or abort completes the unsubscribe without a disconnect, and the unsubscribe is acknowledged with success. The upstream scripts acknowledge in-flight deliveries before the UNSUBSCRIBE. Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…t and keep the membership when a state write fails Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
… mqtt server script Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
… the accepted stream Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…e after the first echo Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…ate is durable Memberships were reconciled when the session state was written to Kafka, so a failed write left the registry count lower than the subscriptions that the persisted state still holds. Reconcile when Kafka echoes the state back. Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
… stop flush Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…pts for the bounded fetch Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…stop flush After the stop flush of an unsubscribe the shared stream releases the next record to the share group instead of delivering it. It writes no ticket and accepts nothing, so the record stays available to the other members. A record already in flight completes first. Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…the record is released Part of #1801 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoV8BXxXeLTJEP4JLG9
…nario with the retained topic describe Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoWETrA5Cn7uqKAtsMH
jfallows
force-pushed
the
feature/mqtt-shared-subscriptions-11-unsubscribe-drain-recovery
branch
from
November 17, 2026 18:36
28d1b73 to
399e363
Compare
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 QoS 2 claim ticket whose subscription is not restored at reconnect stays in the store until session termination and is never redelivered. MQTT 5.0 4.8.2 [4.8.2-4/-5] requires QoS 2 delivery to complete to the same client on reconnect, and 4.4 [MQTT-4.4.0-1] requires unacknowledged PUBLISH and PUBREL to be resent.
The case found by test is UNSUBSCRIBE while a QoS 2 delivery is in flight. The MQTT server wrote the session state without the subscription as soon as the UNSUBSCRIBE arrived and only then drained the in-flight acknowledgements. A disconnect mid-drain left a PUBLISH-sent or PUBREL-pending ticket in the store with no subscription restored on reconnect.
Rather than add a stream that is not tied to a subscription, which has no established pattern (the MQTT server only opens subscribe streams for subscriptions in the session state), the subscription now stays in the session state until the drain completes, so recovery runs through the existing restored-subscription path.
binding-mqtt
binding-mqtt-kafka
Part of #1801
Stack
Layer 11 of the stack of PRs for #1801, based on #3156 (layer 10). See #3154 for the full table.
Maintainer decisions
Tests
Written first and seen failing for the right reason (all 7 shared in-flight
UnsubscribeITscenarios andPipelineITqos1/qos2 before the server change; "unexpected store operation delete memberships" for the failed state write; a timeout for the release scenarios).specs/binding-mqtt.spec:UnsubscribeIT(network v4 and v5, application) andUpstreamIT.specs/binding-mqtt-kafka.spec:MqttITandKafkaIT.runtime/binding-mqtt: fullverify.runtime/binding-mqtt-kafka: fullverify../mvnw checkstyle:checkon both bindings and both spec modules: 0 violations../mvnw clean install): BUILD SUCCESS.Registry and memberships invariants are asserted, via the test store assertions, by:
MqttKafkaSessionProxyIT.shouldRetainSharedMembershipWhenStateWriteFails(new): nothing after the membership put when the write fails.MqttKafkaSessionProxyIT.shouldLeaveSharedSubscriptionOnUnsubscribeand its second variant (existing): membership delete, then registry replace0:1to0:0.MqttKafkaSubscribeProxyIT.shouldSubscribeSharedUnsubscribeInflightQos2DisconnectRecoverPublishSentand...PubrelPending(new): membership and registry untouched across a mid-drain disconnect; ticket put, put, delete.MqttKafkaSubscribeProxyIT.shouldSubscribeSharedUnsubscribeReleaseQos2(new): no ticket written for a released record.The new recovery, release and failed-state-write scenarios are
subscribe.shared.unsubscribe.inflight.qos2.disconnect.recover.{publish.sent,pubrel.pending},subscribe.shared.unsubscribe.release.{qos1,qos2},subscribe.shared.unsubscribe.inflight.then.releaseandsession.unsubscribe.shared.state.write.reset.Real broker
Kafka 4.1.1 with
examples/mqtt.kafka.proxy, using an image built from this branch plus the commit from #3119, and a raw MQTT 5 client. Without that commit, reconnects with a reused client id are disconnected with 0x8E (#3103).The state topic holds two records for the client: the subscribe, and the removal written only after the drain.
Generated by Claude Code