1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Ensure mqtt-close message is published when closing mqtt nodes

The change in 1.3 where we ensure config nodes are closed last broke this behaviour. Previously, the config node would get closed triggering the close message. With the new 1.3 behaviour, the flow nodes are stopped and as soon as the last flow node deregisters itself, the broker node would disconnect without sending the close message.

The fix is to send the close message as part of the deregister flow as that will handle all cases properly
This commit is contained in:
Nick O'Leary 2021-04-14 22:28:25 +01:00
parent b5fda5642f
commit 04a3c4bb22
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -400,7 +400,15 @@ module.exports = function(RED) {
} }
if (Object.keys(node.users).length === 0) { if (Object.keys(node.users).length === 0) {
if (node.client && node.client.connected) { if (node.client && node.client.connected) {
return node.client.end(done); // Send close message
if (node.closeMessage) {
node.publish(node.closeMessage,function(err) {
node.client.end(done);
});
} else {
node.client.end(done);
}
return;
} else { } else {
node.client.end(); node.client.end();
return done(); return done();
@ -639,10 +647,6 @@ module.exports = function(RED) {
this.on('close', function(done) { this.on('close', function(done) {
this.closing = true; this.closing = true;
if (this.connected) { if (this.connected) {
// Send close message
if (node.closeMessage) {
node.publish(node.closeMessage);
}
this.client.once('close', function() { this.client.once('close', function() {
done(); done();
}); });