vinodsr / node-red-contrib-tuya-smart-device

a node-red module for managing tuya smart devices
https://flows.nodered.org/node/node-red-contrib-tuya-smart-device
MIT License
43 stars 15 forks source link

NR crashes after Uncaught Exception (connection timed out) #55

Closed MichalPolanik closed 2 years ago

MichalPolanik commented 3 years ago

Every time when the smart device is turned off or there is a problem with connection with device, Node-Red crashes with an error message.

Release 4.0.1:

kwi 15 20:19:11 DietPi node-red[23385]: 15 Apr 20:19:11 - [red] Uncaught Exception:
kwi 15 20:19:11 DietPi node-red[23385]: 15 Apr 20:19:11 - Error: connection timed out
kwi 15 20:19:11 DietPi node-red[23385]: at Socket.<anonymous> (/mnt/dietpi_userdata/node-red/node_modules/tuyapi/index.js:442:18)
kwi 15 20:19:11 DietPi node-red[23385]: at Object.onceWrapper (node:events:435:28)
kwi 15 20:19:11 DietPi node-red[23385]: at Socket.emit (node:events:329:20)
kwi 15 20:19:11 DietPi node-red[23385]: at Socket._onTimeout (node:net:470:8)
kwi 15 20:19:11 DietPi systemd[1]: node-red.service: Main process exited, code=exited, status=1/FAILURE
kwi 15 20:19:11 DietPi systemd[1]: node-red.service: Unit entered failed state.
kwi 15 20:19:11 DietPi systemd[1]: node-red.service: Failed with result 'exit-code'.

And previously for the version 3.1.0:

kwi 15 11:55:35 DietPi node-red[20850]: 15 Apr 11:55:35 - [red] Uncaught Exception:
kwi 15 11:55:35 DietPi node-red[20850]: 15 Apr 11:55:35 - Error: connection timed out
kwi 15 11:55:35 DietPi node-red[20850]:     at Socket.<anonymous> (/mnt/dietpi_userdata/node-red/node_modules/tuyapi/index.js:343:18)
kwi 15 11:55:35 DietPi node-red[20850]:     at Object.onceWrapper (node:events:435:28)
kwi 15 11:55:35 DietPi node-red[20850]:     at Socket.emit (node:events:329:20)
kwi 15 11:55:35 DietPi systemd[1]: node-red.service: Main process exited, code=exited, status=1/FAILURE
kwi 15 11:55:35 DietPi systemd[1]: node-red.service: Unit entered failed state.
kwi 15 11:55:35 DietPi systemd[1]: node-red.service: Failed with result 'exit-code'.

or

kwi 13 23:40:58 DietPi node-red[11340]: 13 Apr 23:40:58 - [info] [tuya-smart-device:xxx] Disconnected from tuyaDevice.
kwi 13 23:40:58 DietPi node-red[11340]: 13 Apr 23:40:58 - [error] [tuya-smart-device:xxx] Error: Error from socket
kwi 13 23:40:58 DietPi node-red[11340]: 13 Apr 23:40:58 - [red] Uncaught Exception:
kwi 13 23:40:58 DietPi node-red[11340]: 13 Apr 23:40:58 - Error: connect ECONNRESET 192.168.0.113:6668
kwi 13 23:40:58 DietPi node-red[11340]:     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1128:16)
kwi 13 23:40:58 DietPi systemd[1]: node-red.service: Main process exited, code=exited, status=1/FAILURE
kwi 13 23:40:58 DietPi systemd[1]: node-red.service: Unit entered failed state.
kwi 13 23:40:58 DietPi systemd[1]: node-red.service: Failed with result 'exit-code'.

Node-Red v1.2.3. Device model : NanoPi M1/T1 (armv7l), DietPi v7.0.2. The device I connect to is a smart plug Gosund SP111.

vinodsr commented 3 years ago

I am unable to replicate the error in my setup with node-red version 1.2.3

Can you please share the steps to create this error. In my case if the device is powered off, then the following message is logged

18 Apr 19:31:51 - [error] [tuya-smart-device:Monitor Plug] find() timed out. Is the device powered on and the ID or IP correct?
18 Apr 19:31:51 - [info] [tuya-smart-device:Monitor Plug] Cannot find the device, re-trying...

How to create the socket error ?

MichalPolanik commented 3 years ago

In my case disconnecting the device from the power supply ends with an uncaught exception every time:

kwi 21 09:46:23 DietPi node-red[10502]: 21 Apr 09:46:23 - [info] [tuya-smart-device:xxx] initiating the find command
kwi 21 09:46:27 DietPi node-red[10502]: 21 Apr 09:46:27 - [info] [tuya-smart-device:xxx] Connected to device! 4780123456f520f448b4
kwi 21 09:46:29 DietPi node-red[10502]: 21 Apr 09:46:29 - [info] [tuya-smart-device:xxx] Data from device: {"devId":"4780123456f520f448b4","dps":{"4":23,"5":57},"t":1618991188}
kwi 21 09:46:34 DietPi node-red[10502]: 21 Apr 09:46:34 - [info] [tuya-smart-device:xxx] Data from device: {"devId":"4780123456f520f448b4","dps":{"6":2379},"t":1618991193}
kwi 21 09:46:39 DietPi node-red[10502]: 21 Apr 09:46:39 - [info] [tuya-smart-device:xxx] Data from device: {"devId":"4780123456f520f448b4","dps":{"6":2376},"t":1618991198}
~~ I PULLED THE PLUG FROM THE SOCKET ~~
kwi 21 09:49:09 DietPi node-red[10502]: 21 Apr 09:49:09 - [info] [tuya-smart-device:xxx] Disconnected from tuyaDevice.
kwi 21 09:49:15 DietPi node-red[10502]: 21 Apr 09:49:15 - [red] Uncaught Exception:
kwi 21 09:49:15 DietPi node-red[10502]: 21 Apr 09:49:15 - Error: connection timed out
kwi 21 09:49:15 DietPi node-red[10502]:     at Socket.<anonymous> (/mnt/dietpi_userdata/node-red/node_modules/tuyapi/index.js:442:18)
kwi 21 09:49:15 DietPi node-red[10502]:     at Object.onceWrapper (node:events:435:28)
kwi 21 09:49:15 DietPi node-red[10502]:     at Socket.emit (node:events:329:20)
kwi 21 09:49:15 DietPi systemd[1]: node-red.service: Main process exited, code=exited, status=1/FAILURE
kwi 21 09:49:15 DietPi systemd[1]: node-red.service: Unit entered failed state.
kwi 21 09:49:15 DietPi systemd[1]: node-red.service: Failed with result 'exit-code'.

The problem also occurs when the device has access to power but there is a connection problem for some reason.

vinodsr commented 3 years ago

Request you to try the following scenario as well.

1 .Add a catch node to the same flow.

  1. Unplug the device .

Is it still crashing node red

MichalPolanik commented 3 years ago

1 .Add a catch node to the same flow.

  1. Unplug the device . Is it still crashing node red

Actually I had this node all the time. It doesn't matter whether I have catch node in this flow or not - after unplug device from the socket, Node-Red crashes literally every time.

But I have noticed, that when I start Node-Red service before plugging the device into the socket, the messages appear, thant you mentioned before:

I will also mention, that I have three the same devices (SP111) in different rooms, so I have three tuya-smart-device nodes in one flow. Of course every device have different virtual ID, IP address and key.

All this time, I performed tests on the 1st device, which I marked as xxx in the logs, so in order to eliminate the defectiveness of the device itself, I decided to check whether the 2nd device (let's call it yyy) would have the same problems. Immediately after unplug the yyy device, Node-Red crashed.

DarkerChild commented 3 years ago

I am also having this issue. I have 8 Tuya smart lights (3 different types). If any of them are turned off Node-Red crashes. And it constantly crashes every hour or so even if they are all turned on. The same error is given. I have a catch node in the flows. I'm running V4.0.2 on NR v1.3.4.

9 May 13:22:56 - [red] Uncaught Exception:
9 May 13:22:56 - Error: connection timed out
    at Socket.<anonymous> (C:\Users\wkc41\.node-red\node_modules\tuyapi\index.js:442:18)
    at Object.onceWrapper (node:events:471:28)
    at Socket.emit (node:events:365:28)
    at Socket._onTimeout (node:net:475:8)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

Edit: I have moved my Node-Red to the version you listed above and it has not crashed since.

fah commented 3 years ago

Same problem here. I have one device that is connected via a wifi-repeater. This connection is sometimes not stable.

NR 2.3.0. in ioBroker 5.1.4 on an Rpi4 node-red-contrib-tuya-smart-device@4.0.2

/opt/iobroker/log/iobroker.2021-06-04.log :

2021-06-04 00:00:35.857  - ^[[31merror^[[39m: node-red.0 (1756) 4 Jun 00:00:35 - [error] [tuya-smart-device:WP] Error: Error from socket: connect EHOSTUNREACH 192.168.10.191:6668
    at Socket.<anonymous> (/opt/iobroker/node_modules/node-red-contrib-tuya-smart-device/node_modules/tuyapi/index.js:492:30)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

2021-06-04 00:00:35.860  - ^[[31merror^[[39m: node-red.0 (24670) Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, o$
2021-06-04 00:00:35.865  - ^[[31merror^[[39m: node-red.0 (24670) unhandled promise rejection: connect EHOSTUNREACH 192.168.10.191:6668
2021-06-04 00:00:35.867  - ^[[31merror^[[39m: node-red.0 (24670) Error: connect EHOSTUNREACH 192.168.10.191:6668
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
2021-06-04 00:00:35.868  - ^[[31merror^[[39m: node-red.0 (24670) Exception-Code: EHOSTUNREACH: connect EHOSTUNREACH 192.168.10.191:6668
2021-06-04 00:00:36.395  - ^[[33mwarn^[[39m: node-red.0 (24670) Terminated (UNCAUGHT_EXCEPTION): Without reason

I have no clue about node.js. But maybe this helps:

A search for

emitErrorNT (internal/streams/destroy.js:92:8)

yielded https://stackoverflow.com/questions/62416274/econnreset-error-crashing-nodejs-application

Other idea was promise and crashes: https://stackoverflow.com/questions/21800010/how-do-i-handle-errors-with-promises

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

Auto closing the issue