andreypopov / node-red-contrib-miio-roborock

Xioami Roborock node-red nodes
Apache License 2.0
30 stars 11 forks source link

Node-red crashes at startup with 2.1.2 addMembership EADDRINUSE #28

Open 0rsa opened 3 years ago

0rsa commented 3 years ago

Describe issue Just updating from node-red-contrib-miio-roborock 2.0.7 to 2.1.2, node-red crashes at startup, even with a fresh system restart

Screens / Logs

27 Mar 04:21:12 - Error: addMembership EADDRINUSE at Socket.addMembership (dgram.js:828:11) at /root/.node-red/node_modules/node-mihome/lib/protocol-aqara.js:48:26 at Array.forEach () at /root/.node-red/node_modules/node-mihome/lib/protocol-aqara.js:46:26 at Array.forEach () at Socket. (/root/.node-red/node_modules/node-mihome/lib/protocol-aqara.js:44:38) at Socket.emit (events.js:327:22) at Socket.EventEmitter.emit (domain.js:467:12) at startListening (dgram.js:149:10) at dgram.js:344:7 at processTicksAndRejections (internal/process/task_queues.js:81:21)

Hardware / Software Debian Buster Node-red 1.2.9

Downgrading to 2.0.7, node-red starts fine.

andreypopov commented 3 years ago

nodejs version?

0rsa commented 3 years ago

@andreypopov 14.16.0

0rsa commented 3 years ago

I tried with 15.12.0, same behaviour:

27 Mar 19:06:56 - [info] Node-RED version: v1.2.9 27 Mar 19:06:56 - [info] Node.js version: v15.12.0 27 Mar 19:06:56 - [info] Linux 4.19.0-14-amd64 x64 LE 27 Mar 19:06:57 - [info] Loading palette nodes SmartthingsConfigNode 27 Mar 19:06:58 - [red] Uncaught Exception: 27 Mar 19:06:58 - Error: addMembership EADDRINUSE at Socket.addMembership (node:dgram:849:11) at /root/.node-red/node_modules/node-mihome/lib/protocol-aqara.js:48:26 at Array.forEach () at /root/.node-red/node_modules/node-mihome/lib/protocol-aqara.js:46:26 at Array.forEach () at Socket. (/root/.node-red/node_modules/node-mihome/lib/protocol-aqara.js:44:38) at Socket.emit (node:events:381:22) at Socket.emit (node:domain:470:12) at startListening (node:dgram:168:10) at node:dgram:363:7 at processTicksAndRejections (node:internal/process/task_queues:82:21)

andreypopov commented 3 years ago

looks like a conflict, do you have nodes connected with xiaomi ? give me the list

0rsa commented 3 years ago

"dependencies": { "miio": "github:kingkong123/miio", "moment": "^2.29.1", "node-mihome": "0.0.27", "node-red-contrib-contextbrowser": "0.0.4", "node-red-contrib-deconz": "~1.3.2", "node-red-contrib-eesmart-d2l": "~0.1.0", "node-red-contrib-google-smarthome": "~0.0.63", "node-red-contrib-miio-roborock": "~2.0.8", "node-red-contrib-multipart-stream-decoder": "0.0.4", "node-red-contrib-nanoleaf-aurora": "~0.2.2", "node-red-contrib-netatmo": "~0.2.0", "node-red-contrib-nexmo": "~3.3.1", "node-red-contrib-rfxcom": "~2.11.3", "node-red-contrib-smartthings": "0.0.20", "node-red-contrib-stackhero-mysql": "~1.0.5", "node-red-contrib-sunevents": "~3.0.3", "node-red-contrib-wled": "0.0.4", "node-red-contrib-yeelight": "~1.0.7", "node-red-contrib-zwave-js": "~3.1.2", "node-red-gardena": "file:../../home/flo/node-red-modules/node-red-gardena", "node-red-node-ping": "~0.3.0", "node-red-node-rbe": "~0.5.0", "node-red-node-suncalc": "~1.0.1", "node-red-node-tail": "~0.3.0", "openzwave-shared": "^1.7.2", "passport-google-oauth": "^2.0.0", "sodium": "^3.0.2", "suncalc": "^1.8.0" }

0rsa commented 3 years ago

I removed miio and node-mihome which are old dependencies. Error persists.

0rsa commented 3 years ago

Ok so I commented api.js l.6 and it starts : mihome.aqaraProtocol.init();

Why you need to init zigbee connection for roborocks? Also, even with 2.2.2, I have exceptions which cause node red to crash completely.

28 Mar 07:00:59 - [warn] [miio-roborock-server:S7] Miio Roborock Error: Could not connect to device, handshake timeout This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: Error: Could not connect to device, handshake timeout at Timeout._onTimeout (/root/.node-red/node_modules/node-red-contrib-miio-roborock/node_modules/miio/lib/network.js:427:17) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)

It started with 2.0.7 a few days ago, my node red crashs a lot of times per day due to node-red-contrib-miio-roborock.


Edit: as it's a warning only, maybe this last crash (first using 2.2.2) is due to something else. Server is up and running, I will see in next hours if it keeps crashing due to node-red-contrib-miio-roborock or not.

I have an idea about EADDRINUSE, I use two roborocks, maybe can it be related to 2 instances of aqara initiated?

becmar39 commented 3 years ago

Maybe the same as in #19

mobamoba commented 3 years ago

I'm having the same issue with 2.1.2 and I can see that the address conflict is with port 9898 which, in my case, is the port used by the Xiaomi Gateway. Perhaps knowing that will help lead to a solution.

andreypopov commented 2 years ago

Please, test this version

node-red-contrib-miio-roborock@2.3.0

dprokscha commented 2 years ago

Well, yes. I am the guy from #38 and I have the same issue. Downgrading to 2.0.7 solves the issue for me too. I am encountering this error on a fresh clean install of Node-RED. My environment:

As mentioned: It is a fresh clean install - no other modules are installed (except of the Pi specific ones which were installed by default).

I did some investigations and found out, that this error does not occur if I am using Ubuntu Server 20.04 LTS (64-bit). So maybe it is related to the underlaying OS. I also doublechecked if any ports (especially 9898) are already in use - but they aren't. The big questions are:

I don't know where to start but maybe this hint with the underlaying OS is enough to help @andreypopov debugging this issue. Please let me know if you need any further information 😜

mobamoba commented 2 years ago

I haven't upgraded my OS (18.04 here) and have the same problem so thinking an OS upgrade isn't the issue.

andreypopov commented 2 years ago

I have ubuntu too.( I tried to create 5 instances of configuration, so I had 5 connects to roborock and everything worked well. Do you have other plugins which are connected with mihome, aqara ? Do you have telegram? can u write to me and we will debug this issue together? @andrey_p3

dprokscha commented 2 years ago

Hm, now I was able to update to 2.3.1 😂

The only thing what changed: I noticed multiple IPs for my network interface "eth0" - one static as mentioned above and another dynamic one. The last one exists because of a misconfiguration of netplan. I deleted the property "dhcp4" from the configuration to get my static IP. But the right way is to set it to "false". Otherwise you'll get the unwanted dynamic IP, because the default value from "dhcp4" seems to be "true".

I am supposing that Node-RED/miio is not handling multiple IPs the right way. It tries to bind the server port 9898 multiple times. Maybe this leads to the error "EADDRINUSE".

@mobamoba: Can you please share your output for "ip address show" to doublecheck my assumption?

mobamoba commented 2 years ago

Sure:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 10:02:b5:31:cd:92 brd ff:ff:ff:ff:ff:ff inet 192.168.1.46/24 brd 192.168.1.255 scope global noprefixroute wlp2s0 valid_lft forever preferred_lft forever inet6 fe80::1202:b5ff:fe31:cd92/64 scope link valid_lft forever preferred_lft forever

dprokscha commented 2 years ago

This is really interesting. Your network configuration seems to be OK. The only difference to mine is that you are using WIFI only.

The root cause in my case is definitely the configuration of netplan and the unwanted dynamic IP via "dhcp4". If I toggle "dhcp4" to "true" and I have both, a static and a dynamic IP, I can reproduce the error. If "dhcp4" is "false" (static IP only), everything is fine and is working as expected.

In your case @mobamoba something different is consuming the port 9898. Maybe it is another module, another instance of Node-RED, another process or Node-Red/miio has trouble with your network configuration in some way.

But I have no clue to be honest - sounds like you need a debugging session with Andrey...

mobamoba commented 2 years ago

I use a different Xiaomi node to control my Xiaomi Gateway and all my Aqara sensors. The problem, for me, is that the later versions of this app included something that forced the use of 9898 which is impossible in my system and is actually unnecessary as I'm using 2.0.7 - which doesn't have the 9898 conflict - and it controls my Roborock perfectly.

I think the solution lies in removing whatever got added that is now using 9898 and remove that. What exactly is in this node that's using 9898 now and that wasn't using it in 2.0.7?

B0rax commented 2 years ago

Ok so I commented api.js l.6 and it starts : mihome.aqaraProtocol.init();

Just fyi. This Issue here is still in the newest version. I did uncomment the line that you mentioned and it fixed the issue for me.

@andreypopov what does this line do? In my testing (a few months now) it seems to work just fine without this line.

mobamoba commented 2 years ago

I'm pretty sure the issue is here in node mihome:

https://github.com/maxinminax/node-mihome/blob/master/lib/protocol-aqara.js const MULTICAST_ADDRESS = '224.0.0.50'; const MULTICAST_PORT = 4321; const SERVER_PORT = 9898;

If port 9898 is in use, as it is in my case, this node fails and prevents node-red from loading. I don't know about the multicast stuff.

DeadEnded commented 2 years ago

I just had this happen today without any changes in NR or pallet, etc. after a restart of the container. I did some digging and found MY cause - which might shed some light on this and help fix it.

Firstly, my error looked like this (log from portainer - might not be as detailed, but it was enough):

10 May 10:06:19 - [red] Uncaught Exception:
10 May 10:06:19 - [error] Error: addMembership EADDRINUSE
    at Socket.addMembership (dgram.js:850:11)
    at /data/node_modules/node-mihome/lib/protocol-aqara.js:48:26
    at Array.forEach (<anonymous>)
    at /data/node_modules/node-mihome/lib/protocol-aqara.js:46:26
    at Array.forEach (<anonymous>)
    at Socket.<anonymous> (/data/node_modules/node-mihome/lib/protocol-aqara.js:44:38)
    at Socket.emit (events.js:412:35)
    at startListening (dgram.js:172:10)
    at dgram.js:364:7
    at processTicksAndRejections (internal/process/task_queues.js:83:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-red-docker@2.2.2 start: `node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"`
npm ERR! Exit status 1

As @mobamoba pointed out, the protocol-auara.js appears to be part of the issue. Looking at this class, there are indeed some static ports. For me though, this might not have been the issue. My error points to Socket.addMembership called from protocol-aquara.js line 48. I can see that the init that was commented out to fix this, calls the createSocket. The createSocket is right below it, and contains the code where the error is happening.

image

Now, I see that in this line it is specifically looking for Multicast_Address - nothing to do with the ports. I scratched my head for a bit... then I realized last week I was messing around with adding a second IP to my system. So I checked out netplan and sure enough I had not removed my testing. I had defined a second IP for my ethernet port. I removed this, restarted Node-Red, and it's fixed!

So - I know that was a lot of information - but I hope my digging into this might help shed light on what is really causing the issue. For me, it was having two IP addresses defined. I assume the code opened the port on the first address, and then when it tried to do it again on the second, it threw the error. How to gracefully handle this - that is outside of my knowledge currently. It does appear to be a bug on the protocol-auara.js though.

I'll going to submit this as an issue to that repo - maybe it will help them fix this!

Cheers! DeadEnd