Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HomekitRoot leaks connections in it's subscriptionManager when calling "start" then "stop" #54

Closed
timcharper opened this issue Jan 21, 2019 · 1 comment

Comments

@timcharper
Copy link
Contributor

I've come to notice this issue when working on the Homekit extension for Openhab2. When I reload the bundle, it calls homekitRoot.stop(), followed by a reload of the Java classes, followed by a homekitRoot.start(). What I'm noticing is that the subscriptions from before are accumulating, resulting in more and more SubscriptionManager::publish calls with each reload.

Here's what I'll see in the logs when toggling a homekit switch from the iOS client during the first load:

11:22:58.773 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328

Then, after, say, 5 reloads of the bundle (resulting in a call to HomekitRoot::stop() and HomekitRoot::start() each time, toggling a switch from the iOS client will cause that message to be logged an additional five times:

12:03:21.146 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328
12:03:21.146 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328
12:03:21.146 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328
12:03:21.146 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328
12:03:21.146 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328
12:03:21.146 [INFO ] [.impl.connections.SubscriptionManager] - Publishing changes for 612672328

After digging around, it looks like characteristic.unsubscribe() in SubscriptionManage.java#L71 isn't getting called during stop(). I added some log messages to log when a connection is removed via SubscriptionManager::removeConnection() and SubscriptionManager::removeSubscription(...), and neither are invoked nor do connections appear to be ever removed. I'm not sure what mechanism is expected to clean these up, but the failure to have these cleaned up is what's leading to the accumulation of characteristic subscriptions.

timcharper added a commit to timcharper/HAP-Java that referenced this issue Jan 21, 2019
@timcharper
Copy link
Contributor Author

An attempt to fix this is seen in commit 7e8f98e

timcharper added a commit to timcharper/HAP-Java that referenced this issue Jan 28, 2019
andylintner pushed a commit that referenced this issue Feb 3, 2019
Remove all subscriptions during homekitRoot.stop()

This is a potential fix for #54
ccutrer pushed a commit to ccutrer/openhab-addons that referenced this issue Feb 13, 2019
timcharper added a commit to hap-java/openhab2-addons that referenced this issue Feb 27, 2019
ccutrer pushed a commit to ccutrer/openhab-addons that referenced this issue Mar 3, 2019
timcharper added a commit to hap-java/openhab2-addons that referenced this issue Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant