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

Don't end mqtt client on first error

Fixes #1566
This commit is contained in:
Nick O'Leary 2018-01-25 16:58:42 +00:00
parent e6369820a9
commit 45913e5ee8
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -184,6 +184,8 @@ module.exports = function(RED) {
this.connect = function () { this.connect = function () {
if (!node.connected && !node.connecting) { if (!node.connected && !node.connecting) {
node.connecting = true; node.connecting = true;
console.log("going for connect");
try {
node.client = mqtt.connect(node.brokerurl ,node.options); node.client = mqtt.connect(node.brokerurl ,node.options);
node.client.setMaxListeners(0); node.client.setMaxListeners(0);
// Register successful connect or reconnect handler // Register successful connect or reconnect handler
@ -243,12 +245,11 @@ module.exports = function(RED) {
}); });
// Register connect error handler // Register connect error handler
node.client.on('error', function (error) { // The client's own reconnect logic will take care of errors
if (node.connecting) { node.client.on('error', function (error) {});
node.client.end(); }catch(err) {
node.connecting = false; console.log(err);
} }
});
} }
}; };