Repository navigation
Keep HiveMQ inbound subscription in step with start and stop - #11732
Open
akshit-khandelwal47 wants to merge 1 commit into
Open
akshit-khandelwal47 wants to merge 1 commit into
akshit-khandelwal47 wants to merge 1 commit into
Conversation
The `Mqtt3MessageDrivenChannelAdapter` and `Mqtt5MessageDrivenChannelAdapter` subscribe and unsubscribe asynchronously, and `isSubscribed` changes only when the broker acknowledges. `doStart()` and `doStop()` decide from that flag, so they act on a stale state when they run within one broker round trip of each other: * `stop()` followed by `start()`: `start()` still sees `isSubscribed` and skips the subscription, the UNSUBACK then clears it, and the running adapter receives nothing * `start()` followed by `stop()`: `stop()` does not see `isSubscribed` yet and skips the unsubscription, the SUBACK then sets it, and the stopped adapter keeps sending messages to its output channel Fix: * Track an in-flight unsubscription with `isUnsubscribing`, as `isSubscribing` does for the subscription * When the SUBACK arrives for an adapter that is no longer active, unsubscribe * When the UNSUBACK arrives for an adapter that is active again, subscribe Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Akshit Khandelwal <akshitkhandelwal20@gmail.com>
artembilan
approved these changes
Nov 16, 2026
artembilan
left a comment
Member
There was a problem hiding this comment.
LGTM.
We will merge this next week when we start 7.2.1 patch version.
Thanks
This branch has not been deployed
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.
The HiveMQ-based
Mqtt3MessageDrivenChannelAdapterandMqtt5MessageDrivenChannelAdaptersubscribe and unsubscribe asynchronously, andisSubscribedonly changes when the broker acknowledges.doStart()anddoStop()decide from that flag, so when they run within one broker round trip of each other they act on a stale state:stop()thenstart():start()still seesisSubscribed == trueand skips the subscription. The UNSUBACK then clears the flag, and the adapter is running but not subscribed, so it receives nothing, with no error or warning.start()thenstop():stop()doesn't seeisSubscribedyet and skips the unsubscription. The SUBACK then sets the flag, and the stopped adapter keeps sending messages to its output channel.Against the Mosquitto container from the module's tests,
adapter.stop(); adapter.start();leaves the adapter withisRunning() == trueandisSubscribed == false, and a message published afterwards never arrives. With a one second pause betweenstop()andstart()it works. So anything that restarts an adapter faster than the broker answers hits this, and the window grows with the round trip to the broker.I found this while reading the new 7.2 HiveMQ adapters, not from a production system.
The fix keeps the existing flags and lets the acknowledgment callbacks catch up with the lifecycle:
isUnsubscribingtracks an in-flight unsubscription, asisSubscribingalready does for the subscription, so the two operations don't overlap.AbstractEndpointsetsactivebeforedoStart()and clears it beforedoStop(), so a callback that updates its flag and then checksisActive()can't miss a concurrent start or stop.testStartRightAfterStopSubscribesAgainandtestStopRightAfterStartUnsubscribesinMqtt3MessageDrivenChannelAdapterTestsandMqtt5MessageDrivenChannelAdapterTestsfail onmainand pass with the change. Removing either half of the fix fails the matching two tests again../gradlew :spring-integration-mqtt-client:checkpasses locally, and the adapter tests passed 5 runs in a row.I used Claude Code (Claude Opus 5.5) to help with this. The commit credits it in a
Co-authored-bytrailer.🤖 Generated with Claude Code