plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API
MIT License
1.03k stars 142 forks source link

TCP timeouts in 1.2.0 #77

Closed gtalusan closed 2 years ago

gtalusan commented 5 years ago

I have 5 switches running under node-red with tplink-smarthome-api 1.2.0, and I've noticed that it's been accumulating hundreds of sockets in TIME_WAIT such that the switches eventually become non-responsive over the network.

I've modified the 1.2.0 code a bit to call socket.destroy() on timeout, but noticed that the particular code no longer exists in master.

Can we get a new release, please?

bladerunner2020 commented 5 years ago

@gtalusan could. you share your modification, please?

aldichollow commented 5 years ago

@gtalusan I would also like to know about the modification.

gtalusan commented 5 years ago

I've only modified smart-plug.js since I use TP-Link switches, and not the outlets (yet).

Not sure if this patch is causal, but my uptime has been several weeks now without a restart of node-red.

Hopefully it helps, but if it doesn't.... YMMV.

--- smart-plug.js.bak   2019-06-06 21:07:44.123569208 -0400
+++ smart-plug.js   2019-11-27 09:36:13.100786542 -0500
@@ -56,12 +56,15 @@
         });
         node.startPolling();
       })
-      .catch(() => {
-        return node.handleConnectionError();
+      .catch((error) => {
+        return node.handleConnectionError(error);
       });
     };

     node.disconnectClient = function () {
+      node.debug('disconnecting client!');
+      delete node.deviceInstance;
+      node.deviceInstance = null;
       node.deviceConnected = false;
     };

@@ -292,4 +295,4 @@
     });
   });

-};
\ No newline at end of file
+};
caseyjhol commented 4 years ago

@plasticrake I've been encountering a similar issue using https://github.com/caseyjhol/node-red-contrib-tplink (using smart-plug with an HS220):

TCP 192.168.1.83:9999 Error: TCP Timeout
    at Timeout._onTimeout (/config/node-red/node_modules/tplink-smarthome-api/lib/network/tcp-socket.js:62:22)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

...

TCP 192.168.1.83:9999 Error: connect EHOSTUNREACH 192.168.1.83:9999
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16) {
  errno: 'EHOSTUNREACH',
  code: 'EHOSTUNREACH',
  syscall: 'connect',
  address: '192.168.1.83',
  port: 9999
}

tplink-smarthome-api v2.0.0

Every night, when attempting to run a sequence in Node-RED, this error is thrown for one of my switches multiple times. The same TCP error is sent to the polling-error event. Any thoughts?

simlu commented 3 years ago

Running into the same issue, which eventually requires a restart.

plasticrake commented 2 years ago

Closing this as its very old. And the code patch provided is not for this code (this repo has never had a file named "smart-plug.js"). The network code has changed quite a bit as well. Please reopen a new issue with more details or suggestions if you have them. Thanks!