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

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

View File

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