mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Guard against null client in MQTT nodes
Fixes #130 There was a timing window where a client could connect to a broker just as new flows were deployed that would cause the on-connect callback to be called after client has been set to null. This caused an NPE. The fix is to check client isn't null in the event handler.
This commit is contained in:
parent
10b7f402c3
commit
6b3010f95b
@ -84,7 +84,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
client.on('connect',function() {
|
client.on('connect',function() {
|
||||||
|
if (client) {
|
||||||
util.log('[mqtt] connected to broker tcp://'+broker+':'+port);
|
util.log('[mqtt] connected to broker tcp://'+broker+':'+port);
|
||||||
|
|
||||||
connecting = false;
|
connecting = false;
|
||||||
@ -100,6 +100,7 @@ module.exports = {
|
|||||||
//console.log(msg);
|
//console.log(msg);
|
||||||
client.publish(msg.topic,msg.payload,msg.qos,msg.retain);
|
client.publish(msg.topic,msg.payload,msg.qos,msg.retain);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
client.on('connectionlost', function(err) {
|
client.on('connectionlost', function(err) {
|
||||||
util.log('[mqtt] connection lost to broker tcp://'+broker+':'+port);
|
util.log('[mqtt] connection lost to broker tcp://'+broker+':'+port);
|
||||||
|
Loading…
Reference in New Issue
Block a user