Skip to content

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

@timcharper

Description

@timcharper

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions