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.
pull/139/head
Nick O'Leary 2014-01-13 11:27:09 +00:00
parent 10b7f402c3
commit 6b3010f95b
1 changed files with 16 additions and 15 deletions

View File

@ -84,7 +84,7 @@ module.exports = {
}
};
client.on('connect',function() {
if (client) {
util.log('[mqtt] connected to broker tcp://'+broker+':'+port);
connecting = false;
@ -100,6 +100,7 @@ module.exports = {
//console.log(msg);
client.publish(msg.topic,msg.payload,msg.qos,msg.retain);
}
}
});
client.on('connectionlost', function(err) {
util.log('[mqtt] connection lost to broker tcp://'+broker+':'+port);