openhab-addons: [homekit] Binding stops working after a couple of days

Current Behavior

I am using the Homekit binding to make approx. 50 openHAB items available for control via Siri. After a seemingly random amount of time - mostly a couple of days - the binding stops working. The symptoms are that the Home app flags all items with “no response”.

We have two HomePods and an Apple TV. All three are listed as Homekit hubs in the Home app settings. We tried to reboot the device shown as “connected” (as opposed to “standby”) in the Home app settings when the problem occurred. But that didn’t help.

If I check Karaf console, I can see that a ConcurrentModificationException has been logged. The following is an abbreviated copy & paste of my Karaf console output spanning approx two weeks and showing two consecutive incidents. Although I am not 100% sure that the Exception is directly related to the issue it was there every time I checked the server after Homekit stopped working. As can be seen I can correct the issue if I just restart the binding. Seconds later all Homekit items become responsive again.

                           _   _     _     ____  
   ___   ___   ___   ___  | | | |   / \   | __ ) 
  / _ \ / _ \ / _ \ / _ \ | |_| |  / _ \  |  _ \ 
 | (_) | (_) |  __/| | | ||  _  | / ___ \ | |_) )
  \___/|  __/ \___/|_| |_||_| |_|/_/   \_\|____/ 
       |_|       3.1.0-SNAPSHOT - Build #2101

...

openhab> Exception in thread "SocketListener(macmini-2012-fritz-box.local.)" java.util.ConcurrentModificationException
	at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043)
	at java.base/java.util.ArrayList$Itr.next(ArrayList.java:997)
	at javax.jmdns.impl.DNSCache.getDNSEntry(DNSCache.java:142)
	at javax.jmdns.impl.JmDNSImpl.handleRecord(JmDNSImpl.java:1362)
	at javax.jmdns.impl.JmDNSImpl.handleResponse(JmDNSImpl.java:1476)
	at javax.jmdns.impl.SocketListener.run(SocketListener.java:77)
bundle:list
START LEVEL 100 , List Threshold: 50
 ID │ State  │ Lvl │ Version                 │ Name
────┼────────┼─────┼─────────────────────────┼──────────────────────────────────────────────────────────────
...
227 │ Active │  80 │ 3.1.0.202012260419      │ openHAB Add-ons :: Bundles :: IO :: Homekit
...
openhab> bundle:restart 227

... a couple of days later, no additional output logged ...

openhab> Exception in thread "SocketListener(2a02-908-d81-9640-b0b2-4528-a5a5-dd04-en0.local.)" java.util.ConcurrentModificationException
	at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043)
	at java.base/java.util.ArrayList$Itr.next(ArrayList.java:997)
	at javax.jmdns.impl.DNSCache.getDNSEntry(DNSCache.java:142)
	at javax.jmdns.impl.JmDNSImpl.handleRecord(JmDNSImpl.java:1362)
	at javax.jmdns.impl.JmDNSImpl.handleResponse(JmDNSImpl.java:1476)
	at javax.jmdns.impl.SocketListener.run(SocketListener.java:77)
Exception in thread "SocketListener(macmini-2012-fritz-box.local.)" java.lang.NullPointerException
	at javax.jmdns.impl.JmDNSImpl.handleRecord(JmDNSImpl.java:1373)
	at javax.jmdns.impl.JmDNSImpl.handleResponse(JmDNSImpl.java:1476)
	at javax.jmdns.impl.SocketListener.run(SocketListener.java:77)
bundle:restart 227
openhab>

Steps to Reproduce (for Bugs)

Unfortunately this issue seems to happen at random. I do not know of a way to reproduce it at will.

Your Environment

Here is the output of the Karaf “info” command:

Karaf
  Karaf version               4.2.7
  Karaf home                  /Users/administrator/openhab/runtime
  Karaf base                  /Users/administrator/openhab/userdata
  OSGi Framework              org.eclipse.osgi-3.12.100.v20180210-1608

JVM
  Java Virtual Machine        OpenJDK 64-Bit Server VM version 11.0.9+11
  Version                     11.0.9
  Vendor                      AdoptOpenJDK
  Pid                         29796
  Uptime                      14 days 23 hours
  Process CPU time            11 hours 23 minutes
  Process CPU load            0.00
  System CPU load             0.00
  Open file descriptors       323
  Max file descriptors        10,240
  Total compile time          13 minutes
Threads
  Live threads                312
  Daemon threads              126
  Peak                        356
  Total started               485947
Memory
  Current heap size           371,764 kbytes
  Maximum heap size           4,194,304 kbytes
  Committed heap size         576,512 kbytes
  Pending objects             0
  Garbage collector           Name = 'G1 Young Generation', Collections = 9834, Time = 58.410 seconds
  Garbage collector           Name = 'G1 Old Generation', Collections = 0, Time = 0.000 seconds
Classes
  Current classes loaded      21,664
  Total classes loaded        32,984
  Total classes unloaded      11,320
Operating system
  Name                        Mac OS X version 10.15.7
  Architecture                x86_64
  Processors                  4

I am currently running the 3.1.0-SNAPSHOT of openHAB, but I had this issue with the milestones (and I believe the 3.0 release) as well. It is hard to tell as the milestones sometimes got released faster than the issue usually appears.

As can be seen on the Karaf output the system I am running openHAB on is a mac Mini 2012 running macOS Catalina. The system is used exclusively for openHAB.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (2 by maintainers)

Commits related to this issue

Most upvoted comments

For the moment I am using a simple cron to detect the corrupted state of the bundle to restart it periodically. Not a beauty, but it minimizes the impact… Adjust to your likings. OpenHab is my only homekit bridge at home so I can detect the faulty state by detecting the missing _hap._tcp MDNS entry.

/usr/bin/avahi-browse -t -r _hap._tcp > /root/checkhap/lookup.txt
actualsize=$(/usr/bin/wc -c <"/root/checkhap/lookup.txt")
if [ $actualsize -ge 1 ]; then
    echo size is over $minimumsize bytes. Homekit seems healthy. Aborting...
else
    echo size is under $minimumsize bytes. Restarting bundle...
    echo bundle:restart 241 | /usr/bin/openhab-cli console -p habopen  
fi
rm /root/checkhap/lookup.txt

Deactivating IPv6 for my entire Raspberry Pi helped!

https://github.com/jmdns/jmdns/issues/211

There is an open issue at the jmDNS repository

@yfre I’ve been using 3.3.0 Release for quite a while now and the problem is gone. Yes, I am confident that we can close this issue. Thanks a lot for keeping track! 👍

I have the very same issue using a Raspberry Pi 3 Model B. Around 20 HomeKit devices (most of them DIY thermometers and Sonoff switches) and an Apple TV 4 (“HD”).

Here’s the output from systemctl status openhab:

Jan 03 14:17:13 raspberrypi systemd[1]: Started openHAB - empowering the smart home.
Jan 12 04:46:48 raspberrypi karaf[545]: Exception in thread "SocketListener(192-168-178-104.local.)" java.util.ConcurrentModificationException
Jan 12 04:46:48 raspberrypi karaf[545]:         at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043)
Jan 12 04:46:48 raspberrypi karaf[545]:         at java.base/java.util.ArrayList$Itr.next(ArrayList.java:997)
Jan 12 04:46:48 raspberrypi karaf[545]:         at javax.jmdns.impl.DNSCache.getDNSEntry(DNSCache.java:142)
Jan 12 04:46:48 raspberrypi karaf[545]:         at javax.jmdns.impl.JmDNSImpl.handleRecord(JmDNSImpl.java:1362)
Jan 12 04:46:48 raspberrypi karaf[545]:         at javax.jmdns.impl.JmDNSImpl.handleResponse(JmDNSImpl.java:1476)
Jan 12 04:46:48 raspberrypi karaf[545]:         at javax.jmdns.impl.SocketListener.run(SocketListener.java:77)

Also, some general system info:

pi@raspberry:~ $ neofetch
pi@raspberrypi
--------------
OS: Raspbian GNU/Linux 10 (buster) armv7l
Host: Raspberry Pi 3 Model B Rev 1.2
Kernel: 5.4.79-v7+
Uptime: 8 days, 20 hours, 6 mins
Packages: 558 (dpkg)
Shell: bash 5.0.3
Terminal: /dev/pts/0
CPU: BCM2835 (4) @ 1.200GHz
Memory: 331MiB / 924MiB
openhab> info
Karaf
  Karaf version               4.2.7
  Karaf home                  /usr/share/openhab/runtime
  Karaf base                  /var/lib/openhab
  OSGi Framework              org.eclipse.osgi-3.12.100.v20180210-1608

JVM
  Java Virtual Machine        OpenJDK Server VM version 11.0.9.1+1-post-Raspbian-1deb10u2
  Version                     11.0.9.1
  Vendor                      Raspbian
  Pid                         32765
  Uptime                      3 minutes
  Process CPU time            3 minutes
  Process CPU load            0.00
  System CPU load             0.25
  Open file descriptors       273
  Max file descriptors        102,642
  Total compile time          1 minute
Threads
  Live threads                148
  Daemon threads              81
  Peak                        148
  Total started               205
Memory
  Current heap size           69,448 kbytes
  Maximum heap size           229,760 kbytes
  Committed heap size         116,312 kbytes
  Pending objects             0
  Garbage collector           Name = 'Copy', Collections = 74, Time = 1.908 seconds
  Garbage collector           Name = 'MarkSweepCompact', Collections = 6, Time = 2.016 seconds
Classes
  Current classes loaded      17,897
  Total classes loaded        17,912
  Total classes unloaded      15
Operating system
  Name                        Linux version 5.4.79-v7+
  Architecture                arm
  Processors                  4

openhab> bundle:list
[...]
224 │ Active │  80 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: MQTT Broker Binding
225 │ Active │  81 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: MQTT Things and Channels
226 │ Active │  82 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: MQTT HomeAssistant Convention
227 │ Active │  82 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: MQTT Homie Convention
228 │ Active │  80 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: WiFiLED Binding
229 │ Active │  80 │ 3.0.0                   │ openHAB Core :: Bundles :: MQTT Transport
230 │ Active │  80 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: IO :: Homekit
231 │ Active │  80 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: Persistence Service :: RRD4j
232 │ Active │  80 │ 3.0.0                   │ openHAB UI :: Bundles :: Basic UI
233 │ Active │  80 │ 3.0.0                   │ openHAB UI :: Bundles :: Icon Set :: Classic
[...]