TCPGet: Ensure done() is called only once (#1068)

* Add additional safety checks to avoid acting on non-existent objects

* TCPGet: yet more checks

* TCPGet: seperate connected properties

* TCPGet: properly handle node.done()
This commit is contained in:
Nathanaël Lécaudé 2016-11-25 13:14:51 -05:00 committed by Dave Conway-Jones
parent 564902b886
commit b530c1a43d
1 changed files with 27 additions and 3 deletions

View File

@ -541,7 +541,19 @@ module.exports = function(RED) {
if (clients[connection_id]) {
clients[connection_id].connected = false;
}
if (node.done) { node.done(); }
var anyConnected = false;
for (var client in clients) {
if (clients[client].connected) {
anyConnected = true;
break;
}
}
if (node.done && !anyConnected) {
clients = {};
node.done();
}
});
clients[connection_id].client.on('error', function() {
@ -556,6 +568,7 @@ module.exports = function(RED) {
});
clients[connection_id].client.on('timeout',function() {
//console.log("TIMEOUT");
clients[connection_id].connected = false;
node.status({fill:"grey",shape:"dot",text:"tcpin.errors.connect-timeout"});
//node.warn(RED._("tcpin.errors.connect-timeout"));
@ -579,9 +592,20 @@ module.exports = function(RED) {
for (var client in clients) {
clients[client].client.destroy();
}
clients = {};
node.status({});
done();
var anyConnected = false;
for (var c in clients) {
if (clients[c].connected) {
anyConnected = true;
break;
}
}
if (!anyConnected) {
clients = {};
done();
}
});
}