mlfunston / node-red-contrib-broadlink-control

Set of node-red nodes to manage the Broadlink home automation device suite
MIT License
44 stars 24 forks source link

There is a very big issue related to UDP ports handling #4

Closed ivog1 closed 5 years ago

ivog1 commented 5 years ago

Every message sent through given broadlink node creates new UDP listener and this listener stays forever. In result after 64k (max) messages the host system is overloaded with opened UDP ports, NR throws error and restarts itself. To check the growing number of opened ports use this shell command: "netstat -na |grep udp"

Simple solution: As example here is a modified part of SP2Node.js:

...

this.on('input', function (msg) { var conf = RED.nodes.getNode(config.device); var _device; if (conf != null && conf != undefined && conf != "") { var _device = new SP2({ address: conf.host, port: 80 }, conf.mac); } else { var device = new SP2({ address: msg.payload.host.trim(), port: 80 }, new Buffer(msg.payload.mac.replace(':', '').replace('-', '').match(/[0-9A-Fa-f]{2}/g).map(function (num) { return parseInt(num, 16); }))); } // ----------- modification start // IVO: setTimeout( function() { if (typeof (msg.payload) != "object") { msg.payload = {}; } _device.cs.close(); _device = null; }, 3000); // 3 seconds waiting for respond ! // ----------- modification end_ _device.auth();

Best regards, Ivo

mlfunston commented 5 years ago

You're right. I'll have a look at it. Thanks for the info!

mlfunston commented 5 years ago

Thanks for the help, I have updated and closed this. Seems to work ok now from my limited testing.