question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ciao: Accessories deregistered from Bonjour about 1-2min after launching

See original GitHub issue

Describe The Bug:

After updating from an earlier version still using hap-bonjour, when running 0.8.2 (which now uses ciao), all my accessories are properly registered via Bonjour in the _hap.tcp. domain on launch, but disappear after about 1-2min of running, causing homekit to no longer being able to communicate with the devices.

This might be related to #840, even though I do not see the EINVAL log messages mentioned there. However, I’m also not running HAP-NodeJS on macOS, but on Raspbian (RPI 4).

I initially suspected an interaction with mdnsResponder (which is also running on the RPI), but even with mdnsResponder fully stopped/not-running, the behavior is exactly the same.

The setup has been running solidly for years before, and the upgrade now was from 0.7.8 to 0.8.2.

I’d be happy to supply more information or run test apps, if it is helpful.

Addendum: I just tried the beta branch too, since I saw it was quite ahead, but it exhibits the same problem for me.

To Reproduce:

It can be reproduced (for me) from the repository directly, using the demo accessories, e.g. by cloning the repository, then running

npm install
npx tsc
node dist/Core.js

and watching the Bonjour registrations with a tool like dns-sd or a graphical tool like Discovery.

On previous, non-ciao versions, all accessories would more or less register instantly and stay registered rock-solidly (I’ve been running my setup years now, and even automatic re-registrations after the network went down, etc…, used to work fine).

With ciao, I see about one accessory per second registered upon launch (much slower than with hap-bonjour), and all registrations being removed suddenly after about 1-2min.

Expected behavior:

hap-bonjour worked rock-solidly for me without any app restarts in months, but ciao launches much slower on one hand (registering the accessories initially), and stops advertising them apparently after about 1-2min.

Logs:

Here’s a log of watching the _hap._tcp. Bonjour domain with dns-sd on macOS 10.15 when 0.8.2 launches (showing the slow registration rate of one accessory per second), until all accessories are de-registered again (I’ve abbreviated the names of my own accessories for privacy’s sake, but the demo accessories are also included).

$ dns-sd -B _hap._tcp.
Browsing for _hap._tcp.
DATE: ---Sat 14 Nov 2020---
14:53:52.430  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
14:54:17.106  Add        2   5 local.               _hap._tcp.           0
14:54:18.334  Add        2   5 local.               _hap._tcp.           10
14:54:19.098  Add        2   5 local.               _hap._tcp.           11
14:54:20.065  Add        2   5 local.               _hap._tcp.           12
14:54:20.980  Add        2   5 local.               _hap._tcp.           13
14:54:22.540  Add        2   5 local.               _hap._tcp.           13
14:54:24.599  Add        2   5 local.               _hap._tcp.           14
14:54:25.875  Add        2   5 local.               _hap._tcp.           15
14:54:27.201  Add        2   5 local.               _hap._tcp.           16
14:54:28.199  Add        2   5 local.               _hap._tcp.           17
14:54:29.521  Add        2   5 local.               _hap._tcp.           18
14:54:30.521  Add        2   5 local.               _hap._tcp.           19
14:54:31.844  Add        2   5 local.               _hap._tcp.           20
14:54:33.025  Add        2   5 local.               _hap._tcp.           21
14:54:34.295  Add        2   5 local.               _hap._tcp.           22
14:54:35.383  Add        2   5 local.               _hap._tcp.           23
14:54:36.321  Add        2   5 local.               _hap._tcp.           24
14:54:37.390  Add        2   5 local.               _hap._tcp.           25
14:54:38.619  Add        2   5 local.               _hap._tcp.           25
14:54:39.713  Add        2   5 local.               _hap._tcp.           26
14:54:41.244  Add        2   5 local.               _hap._tcp.           27
14:54:43.002  Add        2   5 local.               _hap._tcp.           28
14:54:44.133  Add        2   5 local.               _hap._tcp.           29
14:54:45.190  Add        2   5 local.               _hap._tcp.           30
14:54:46.415  Add        2   5 local.               _hap._tcp.           4
14:54:48.677  Add        2   5 local.               _hap._tcp.           5
14:54:51.205  Add        2   5 local.               _hap._tcp.           6
14:54:52.437  Add        2   5 local.               _hap._tcp.           8
14:54:54.003  Add        2   5 local.               _hap._tcp.           9
14:54:55.229  Add        2   5 local.               _hap._tcp.           Air Conditioner E78C
14:54:56.357  Add        2   5 local.               _hap._tcp.           Remote 871C
14:54:57.349  Add        2   5 local.               _hap._tcp.           IPCamera B1CE
14:54:58.015  Add        2   5 local.               _hap._tcp.           Fan E78C
14:54:58.792  Add        2   5 local.               _hap._tcp.           Garage Door E0CE
14:54:59.833  Add        2   5 local.               _hap._tcp.           Simple Light 83BF
14:55:00.729  Add        2   5 local.               _hap._tcp.           Lock 0C82
14:55:01.957  Add        2   5 local.               _hap._tcp.           Motion Sensor 2CCC
14:55:02.572  Add        2   5 local.               _hap._tcp.           Outlet FFC3
14:55:03.279  Add        2   5 local.               _hap._tcp.           SmartSpeaker 522C
14:55:04.415  Add        2   5 local.               _hap._tcp.           💦 Sprinkler C551
14:55:05.148  Add        2   5 local.               _hap._tcp.           TV 8BF9
14:55:06.260  Add        2   5 local.               _hap._tcp.           Temperature Sensor 1B6A
14:55:06.984  Add        2   5 local.               _hap._tcp.           Thermostat 1 19DA
14:55:07.946  Add        2   5 local.               _hap._tcp.           Wi-Fi Router 0F41
14:55:08.857  Add        2   5 local.               _hap._tcp.           Wi-Fi Satellite 635D
14:55:09.730  Add        2   5 local.               _hap._tcp.           31
14:56:04.321  Rmv        0   5 local.               _hap._tcp.           0
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           11
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           10
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           12
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           13
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           13
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           14
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           15
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           16
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           17
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           18
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           19
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           20
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           21
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           22
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           23
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           24
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           25
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           25
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           26
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           27
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           28
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           29
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           30
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           4
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           5
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           6
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           8
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Air Conditioner E78C
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           9
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Remote 871C
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           IPCamera B1CE
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Fan E78C
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Garage Door E0CE
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Simple Light 83BF
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Lock 0C82
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Motion Sensor 2CCC
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Outlet FFC3
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           SmartSpeaker 522C
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           💦 Sprinkler C551
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           TV 8BF9
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Temperature Sensor 1B6A
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Thermostat 1 19DA
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Wi-Fi Router 0F41
14:56:31.113  Rmv        1   5 local.               _hap._tcp.           Wi-Fi Satellite 635D
14:56:31.113  Rmv        0   5 local.               _hap._tcp.           31

Running HAP-NodeJS with DEBUG=ciao:* doesn’t really yield anything interesting, but here are the debug messages shown last before the de-registration happens:

  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 76 ms): [PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +16s
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 77 ms): [PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 78 ms): [PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 79 ms): [PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 80 ms): [PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 81 ms): [PTR,PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 82 ms): [PTR,PTR,PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 83 ms): [PTR,PTR,PTR,PTR,PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Sending response via unicast to {"address":"192.168.0.77","port":5353,"interface":"eth0"} (took 84 ms): [PTR,PTR] answers and [SRV,TXT,A,AAAA,SRV,TXT,A,AAAA] additionals (UPS: 1440) +1ms
  ciao:Responder Received truncated query from {"address":"192.168.0.77","port":5353,"interface":"eth0"} waiting for more to come! +933ms
  ciao:Responder [192.168.0.77:5353:eth0] Last part of the truncated query arrived. Received 2 packets taking a total of 4 ms +5ms
  ciao:Responder Received truncated query from {"address":"192.168.0.77","port":5353,"interface":"eth0"} waiting for more to come! +3s
  ciao:Responder [192.168.0.77:5353:eth0] Last part of the truncated query arrived. Received 2 packets taking a total of 5 ms +5ms

Initially, each device seems to be registered correctly:

ciao:CiaoService [xxxx] Rebuilding service records... +780ms
ciao:Announcer [xxxx._hap._tcp.local.] Sending announcement number 1 +2ms
ciao:Announcer xxxx._hap._tcp.local.] Sending announcement number 2 +290ms
ciao:Announcer [xxxx._hap._tcp.local.] Sending announcement number 3 +70ms

For reference, here’s the output of dns-sd when launching the older version with hap-bonjour. Note the faster intitial registration (e.g. all accessories appear to Bonjour at nearly the same time), and also note that the reported Flags field seems to be different (3 instead of 2). No de-registrations happen until the node process exits.

$ dns-sd -B _hap._tcp.
Browsing for _hap._tcp.
DATE: ---Sat 14 Nov 2020---
14:57:21.320  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
14:57:25.777  Add        3   5 local.               _hap._tcp.           16
14:57:25.777  Add        3   5 local.               _hap._tcp.           14
14:57:25.777  Add        3   5 local.               _hap._tcp.           22
14:57:25.777  Add        3   5 local.               _hap._tcp.           17
14:57:25.777  Add        3   5 local.               _hap._tcp.           15
14:57:25.777  Add        3   5 local.               _hap._tcp.           19
14:57:25.777  Add        3   5 local.               _hap._tcp.           Wi-Fi Satellite 635D
14:57:25.777  Add        3   5 local.               _hap._tcp.           Lock 0C82
14:57:25.777  Add        3   5 local.               _hap._tcp.           24
14:57:25.777  Add        3   5 local.               _hap._tcp.           Outlet FFC3
14:57:25.777  Add        3   5 local.               _hap._tcp.           11
14:57:25.777  Add        3   5 local.               _hap._tcp.           Air Conditioner E78C
14:57:25.777  Add        3   5 local.               _hap._tcp.           4
14:57:25.777  Add        3   5 local.               _hap._tcp.           Temperature Sensor 1B6A
14:57:25.777  Add        3   5 local.               _hap._tcp.           29
14:57:25.777  Add        3   5 local.               _hap._tcp.           10
14:57:25.778  Add        3   5 local.               _hap._tcp.           💦 Sprinkler C551
14:57:25.778  Add        3   5 local.               _hap._tcp.           Wi-Fi Router 0F41
14:57:25.778  Add        3   5 local.               _hap._tcp.           21
14:57:25.778  Add        3   5 local.               _hap._tcp.           Garage Door E0CE
14:57:25.778  Add        3   5 local.               _hap._tcp.           25
14:57:25.778  Add        3   5 local.               _hap._tcp.           13
14:57:25.778  Add        3   5 local.               _hap._tcp.           0
14:57:25.778  Add        3   5 local.               _hap._tcp.           30
14:57:25.778  Add        3   5 local.               _hap._tcp.           12
14:57:25.778  Add        3   5 local.               _hap._tcp.           20
14:57:25.778  Add        3   5 local.               _hap._tcp.           13
14:57:25.778  Add        3   5 local.               _hap._tcp.           27
14:57:25.778  Add        3   5 local.               _hap._tcp.           IPCamera B1CE
14:57:25.778  Add        3   5 local.               _hap._tcp.           23
14:57:25.778  Add        3   5 local.               _hap._tcp.           9
14:57:25.778  Add        3   5 local.               _hap._tcp.           Simple Light 83BF
14:57:25.778  Add        3   5 local.               _hap._tcp.           5
14:57:25.778  Add        3   5 local.               _hap._tcp.           Remote 871C
14:57:25.778  Add        3   5 local.               _hap._tcp.           Thermostat 1 19DA
14:57:25.778  Add        3   5 local.               _hap._tcp.           26
14:57:25.778  Add        3   5 local.               _hap._tcp.           SmartSpeaker 522C
14:57:25.778  Add        3   5 local.               _hap._tcp.           8
14:57:25.778  Add        3   5 local.               _hap._tcp.           18
14:57:25.778  Add        3   5 local.               _hap._tcp.           28
14:57:25.778  Add        3   5 local.               _hap._tcp.           25
14:57:25.778  Add        3   5 local.               _hap._tcp.           TV 8BF9
14:57:25.778  Add        3   5 local.               _hap._tcp.           6
14:57:25.778  Add        3   5 local.               _hap._tcp.           Motion Sensor 2CCC
14:57:25.778  Add        2   5 local.               _hap._tcp.           Fan E78C
14:57:26.086  Add        2   5 local.               _hap._tcp.           31

Environment:

  • Node.js Version: v14.15.0
  • NPM Version: 6.14.8
  • Operating System: Raspbian
  • Process Supervisor: Systemd

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:47 (40 by maintainers)

github_iconTop GitHub Comments

2reactions
hippotasticcommented, Dec 28, 2020

Great. I’ll test this version with one guy, who continuously had issues as well when running ciao in his multiple subnet network. Maybe we just found the issue I was searching for the last few months 🙃 In any case, I will probably prepare a 0.8.4 release containing the updated ciao 1.1.x release.

Awesome. I’m optimistic that this will solve the other guy’s issues as well, as well as those of many others we may have never heard of because they didn’t open an issue here or comment on one.

I’m happy to have contributed to the solution! 😊

1reaction
Superegcommented, Dec 27, 2020

Doing so will yield an error on platforms like macOS (throwing Adress already in use, event though "reuseaddr": true is set). On linux binding works, but it doesn’t receive any multicast traffic at all. I’ve been there 😅 but yeah, just verified it right now.

Too bad. On Windows, everything works as expected, no matter which version I use (both your original gist, as well as my version with an interface IP to bind to). Well, then I think your proposed loopback address leak solution is the best way to go currently.

I’m starting to think that this is indeed a bug in either the nodejs dgram module or the linux kernel itself(?). Anyways, my proposed workaround is now live with v0.9.0-beta.96, this also “enables” unicast responses by default again. Meaning restoring proper RFC compliant behavior. Would be great if you could quickly verify that it works for you 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found