Skip to content

GH-4014: MQTT ClientManager: completion timeouts #8552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2023

Conversation

artembilan
Copy link
Member

Fixes #4014

The ClientManager implementations uses by mistake a connectionTimeout for operations with completion wait

  • Introduce completionTimeout and disconnectCompletionTimeout for ClientManager abstraction to realign the logic with existing channel adapters and Paho Client by itself.
  • Deprecate DEFAULT_COMPLETION_TIMEOUT and DISCONNECT_COMPLETION_TIMEOUT constants in the AbstractMqttMessageDrivenChannelAdapter in favor of respective replacement in the ClientManager
  • Pull disconnectCompletionTimeout property from the MqttPahoMessageDrivenChannelAdapter to its superclass
  • Use new disconnectCompletionTimeout in the Mqttv5PahoMessageDrivenChannelAdapter for similar disconnectForcibly() call
  • Fix Lifecycle race condition when ClientManager is started by the outbound channel adapter (Integer.MIN_VALUE phase and auto-startup - see DefaultLifecycleProcessor.doStart() and logic around dependencies) which is much earlier than MessageProducerSupport (Integer.MAX_VALUE / 2 phase) and there a connectComplete() callback might be called before the MessageProducerSupport.start(). For that purpose check for an isRunning() in the connectComplete() before subscribing and set readyToSubscribeOnStart flag to subscribe() in a doStart() of this MqttMessageDrivenChannelAdapter
  • Remove redundant MqttPahoMessageDrivenChannelAdapter.cleanSession property in favor of this.clientFactory.getConnectionOptions().isCleanSession() call

GH-8550: MQTT: Always re-subscribe on re-connect

Fixes #8550

Turns out the Paho MQTT client does not re-subscribe when connection re-established on automatic reconnection

  • Fix AbstractMqttMessageDrivenChannelAdapter to always subscribe to their topics in the connectComplete() independently of the reconnect status
  • Verify behavior with MOSQUITTO_CONTAINER image restart in Docker

Fixes spring-projects#4014

The `ClientManager` implementations uses by mistake a `connectionTimeout` for operations with completion wait

* Introduce `completionTimeout` and `disconnectCompletionTimeout` for `ClientManager`
abstraction to realign the logic with existing channel adapters and Paho Client by itself.
* Deprecate `DEFAULT_COMPLETION_TIMEOUT` and `DISCONNECT_COMPLETION_TIMEOUT` constants
in the `AbstractMqttMessageDrivenChannelAdapter` in favor of respective replacement in the `ClientManager`
* Pull `disconnectCompletionTimeout` property from the `MqttPahoMessageDrivenChannelAdapter` to its superclass
* Use new `disconnectCompletionTimeout` in the `Mqttv5PahoMessageDrivenChannelAdapter` for similar `disconnectForcibly()` call
* Fix Lifecycle race condition when `ClientManager` is started by the outbound channel adapter
(`Integer.MIN_VALUE` phase and auto-startup - see `DefaultLifecycleProcessor.doStart()` and logic around `dependencies`)
which is much earlier than `MessageProducerSupport` (`Integer.MAX_VALUE / 2` phase) and there a `connectComplete()` callback
might be called before the `MessageProducerSupport.start()`.
For that purpose check for an `isRunning()` in the `connectComplete()` before subscribing and set `readyToSubscribeOnStart` flag
to `subscribe()` in a `doStart()` of this `MqttMessageDrivenChannelAdapter`
* Remove redundant `MqttPahoMessageDrivenChannelAdapter.cleanSession` property in favor of
`this.clientFactory.getConnectionOptions().isCleanSession()` call

spring-projectsGH-8550: MQTT: Always re-subscribe on re-connect

Fixes spring-projects#8550

Turns out the Paho MQTT client does not re-subscribe when connection
re-established on automatic reconnection

* Fix `AbstractMqttMessageDrivenChannelAdapter` to always subscribe to their topics
in the `connectComplete()` independently of the `reconnect` status
* Verify behavior with `MOSQUITTO_CONTAINER` image restart in Docker
@artembilan
Copy link
Member Author

This PR also includes the fix for #8550.
Otherwise an existing PR for that one is in conflict.

Copy link
Contributor

@garyrussell garyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment/suggestion. Will merge as-is if you prefer.

@garyrussell garyrussell merged commit b482b00 into spring-projects:main Feb 15, 2023
@artembilan artembilan mentioned this pull request Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MQTT is not re-subscribing after reconnect Reusing of MQTT connection (clientId) results in error log "... Never happens."
2 participants