mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3658 from Steve-Mcl/backport-3630
Dont delete TCP socket twice (backport Backport: #3630 to v2.x)
This commit is contained in:
commit
68a2786ff2
@ -432,7 +432,7 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
else {
|
||||
var connectedSockets = [];
|
||||
const connectedSockets = new Set();
|
||||
node.status({text:RED._("tcpin.status.connections",{count:0})});
|
||||
let srv = net;
|
||||
let connOpts;
|
||||
@ -453,16 +453,16 @@ module.exports = function(RED) {
|
||||
});
|
||||
socket.on('close',function() {
|
||||
node.log(RED._("tcpin.status.connection-closed",{host:socket.remoteAddress, port:socket.remotePort}));
|
||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||
node.status({text:RED._("tcpin.status.connections",{count:connectedSockets.length})});
|
||||
connectedSockets.delete(socket);
|
||||
node.status({text:RED._("tcpin.status.connections",{count:connectedSockets.size})});
|
||||
});
|
||||
socket.on('error',function() {
|
||||
node.log(RED._("tcpin.errors.socket-error",{host:socket.remoteAddress, port:socket.remotePort}));
|
||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||
node.status({text:RED._("tcpin.status.connections",{count:connectedSockets.length})});
|
||||
connectedSockets.delete(socket);
|
||||
node.status({text:RED._("tcpin.status.connections",{count:connectedSockets.size})});
|
||||
});
|
||||
connectedSockets.push(socket);
|
||||
node.status({text:RED._("tcpin.status.connections",{count:connectedSockets.length})});
|
||||
connectedSockets.add(socket);
|
||||
node.status({text:RED._("tcpin.status.connections",{count:connectedSockets.size})});
|
||||
});
|
||||
|
||||
node.on("input", function(msg, nodeSend, nodeDone) {
|
||||
@ -475,10 +475,10 @@ module.exports = function(RED) {
|
||||
} else {
|
||||
buffer = Buffer.from(""+msg.payload);
|
||||
}
|
||||
for (var i = 0; i < connectedSockets.length; i += 1) {
|
||||
if (node.doend === true) { connectedSockets[i].end(buffer); }
|
||||
else { connectedSockets[i].write(buffer); }
|
||||
}
|
||||
connectedSockets.forEach(soc => {
|
||||
if (node.doend === true) { soc.end(buffer); }
|
||||
else { soc.write(buffer); }
|
||||
})
|
||||
}
|
||||
nodeDone();
|
||||
});
|
||||
@ -495,12 +495,10 @@ module.exports = function(RED) {
|
||||
} else {
|
||||
node.log(RED._("tcpin.status.listening-port",{port:node.port}));
|
||||
node.on('close', function() {
|
||||
for (var c in connectedSockets) {
|
||||
if (connectedSockets.hasOwnProperty(c)) {
|
||||
connectedSockets[c].end();
|
||||
connectedSockets[c].unref();
|
||||
}
|
||||
}
|
||||
connectedSockets.forEach(soc => {
|
||||
soc.end();
|
||||
soc.unref();
|
||||
})
|
||||
server.close();
|
||||
node.log(RED._("tcpin.status.stopped-listening",{port:node.port}));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user