MQTT.js
MQTT.js copied to clipboard
Client does not resubscribe after reconnect if clean = false
Is there any reason we don't want resubscribe work if clean = false? I have created a sub client with clean = false, and resubscribe = true, the client will not resubscribe the topics if MQTT aedes broker (no persistence) restart. And, sub-client will no longer receive the message of the topics https://github.com/mcollina/aedes
https://github.com/mqttjs/MQTT.js/blob/master/lib/client.js From MQTT.js/lib/client.js
MqttClient.prototype._resubscribe = function () {
if (!this._firstConnection &&
this.options.clean &&
Object.keys(this._resubscribeTopics).length > 0) {
if (this.options.resubscribe) {
this._resubscribeTopics.resubscribe = true
this.subscribe(this._resubscribeTopics)
} else {
this._resubscribeTopics = {}
}
}
I can provide my sub client code and broker code if necessary
@https://github.com/mqttjs/MQTT.js/issues/749
I just ran into this myself with MQTT.js 4.2.8 and using Mosquitto 2.0.12 as the broker, and was extremely surprised by the behaviour. Was there a specific reason for it behaving like this, or is it some unintended bug?
This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.
If this issue is still important, you can simply comment with a "bump" to keep it open.
Thank you for your contribution.
bump
The sessionPresentFlag should be available since version 3.1.1. And it is possible for broker to lose the persistent session, in that case you would want the client to automatically resubscribe.
Thus this line: https://github.com/mqttjs/MQTT.js/blob/18bdd491da7921ede5b90f5ed4bbf2dc46a304ae/src/lib/client.ts#L2108-L2110
Should be:
(this.options.clean || (this.options.protocolVersion >= 4 && !this.connackPacket.sessionPresent)) &&
Right? @robertsLando
This problem seem to be observed in multiple issues #749, #895, #1288
I can make a pull request for this. Not sure if this would be considered a breaking change, But I think most people woud expect resubscribe to work like this.
Yeah that's a bug. Open a PR if possible, remember to add a test. Thanks