openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[Homekit] NPE Exception thrown continuously #5645

Closed digitaldan closed 5 years ago

digitaldan commented 5 years ago

Current Behavior

After enabling the homekit binding, initially it works. After some amount of time, this could be 10 mins or even an hour, the homekit functionality ceases to work ( Home apps show devices are "not responding" ). Aditionally i see this message in my logs , hundreds of times:

2019-05-26 09:10:20.677 [INFO ] [impl.connections.SubscriptionManager] - Publishing changes for 1928283748
2019-05-26 09:10:20.679 [INFO ] [impl.connections.SubscriptionManager] - Publishing changes for 1928283748
2019-05-26 09:10:20.682 [ERROR] [impl.connections.SubscriptionManager] - Failed to create new event message
java.lang.NullPointerException: null
    at com.beowulfe.hap.impl.connections.SubscriptionManager.publish(SubscriptionManager.java:98) ~[?:?]
    at com.beowulfe.hap.impl.connections.SubscriptionManager.lambda$addSubscription$0(SubscriptionManager.java:37) ~[?:?]
    at org.openhab.io.homekit.internal.HomekitAccessoryUpdater.lambda$1(HomekitAccessoryUpdater.java:55) ~[?:?]
    at org.eclipse.smarthome.core.items.GenericItem$1.run(GenericItem.java:262) [133:org.openhab.core:2.5.0.201905172320]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:?]

This has also been reported on the community forums as well. https://community.openhab.org/t/homekit-the-unsetitemregistry-method-has-thrown-an-exception/70942/5?u=digitaldan

Possible Solution

I am guessing that the callback here https://github.com/openhab/openhab2-addons/blob/4ff0808f1859038ff88d9b39a9819f8018866ff4/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAccessoryUpdater.java#L55 is null, and i could submit a patch that checks for that, but my guess is that would not be solving the core issue of why its null.

Steps to Reproduce (for Bugs)

  1. Enable devices in homekit
  2. Let run for awhile

Context

Your Environment

J-N-K commented 5 years ago

Will have a look

J-N-K commented 5 years ago

The root cause is outside of openHAB in the HAP-java library. It requests a subscription with a null callback. I‘ll check how to catch that as early as possible, but it has to be fixed somewhere else.

digitaldan commented 5 years ago

I was wondering if the problem is related to something like how we unregister items and possibly are not removing the callback properly , so its null next time a state is published on the item. But i don't know the code very well, so was kinda a wild guess.

J-N-K commented 5 years ago

Good point. There is at least another flaw (not sure if that is the real problem. When we unset the bridge, we do not remove the accessories from that bridge. Maybe that is, why unsubscribe is not called and an old subscription stays in place. Anyway, I have seen subscribe-requests with a null-callback, that seems to be wrong.

J-N-K commented 5 years ago

I have prepared a fix, would you like to try it? The new .jar is here.

You can update your installation with bundle:update <number> https://janessa.me/esh/org.openhab.io.homekit-fix-npe.jar and probably restarting that bundle.

J-N-K commented 5 years ago

Please open a different issue for that, it is not related. Include your item-configuration and if possible the version it worked with before. Thanks