iotagent-node-lib icon indicating copy to clipboard operation
iotagent-node-lib copied to clipboard

Bidirectional plugin doesn't perform unsubscription on device removal

Open fgalan opened this issue 7 years ago • 10 comments

The library has methods that implementes the unsubscribe operation on CB. In particular, the unsubscribe() function at https://github.com/telefonicaid/iotagent-node-lib/blob/master/lib/services/ngsi/subscriptionService.js#L184

function unsubscribe(device, id, callback) {
    ...
    if (device.cbHost) {
        options.uri = 'http://' + device.cbHost + '/v1/unsubscribeContext';
    } else {
        options.uri = 'http://' + config.getConfig().contextBroker.host + ':' + config.getConfig().contextBroker.port +
            '/v1/unsubscribeContext';
    }
...
}

which is called by removeAllSubscriptions() function at https://github.com/telefonicaid/iotagent-node-lib/blob/master/lib/services/devices/deviceService.js#L415:

function removeAllSubscriptions(device, callback) {
    function removeSubscription(subscription, callback) {
        subscriptions.unsubscribe(device, subscription.id, callback);
    }

    if (device.subscriptions) {
        async.map(device.subscriptions, removeSubscription, callback);
    } else {
        callback(null, {});
    }
}

However, nobody in the library is using this method, as can be checked by this search:

  • https://github.com/telefonicaid/iotagent-node-lib/search?utf8=%E2%9C%93&q=removeAllSubscriptions&type= (0 hits)

In addition, IOTA agents hasn't any link with this code in the library, I mean nobody using it the IOTA JSON agent:

  • https://github.com/telefonicaid/iotagent-json/search?utf8=%E2%9C%93&q=removeAllSubscriptions&type= (0 hits)
  • https://github.com/telefonicaid/iotagent-json/search?utf8=%E2%9C%93&q=unsubscribe&type= (1 hits in no test code but related with MQTT)

and nobody using in the IOTA UL agent:

  • https://github.com/telefonicaid/iotagent-ul/search?utf8=%E2%9C%93&q=removeAllSubscriptions&type= (0 hits)
  • https://github.com/telefonicaid/iotagent-ul/search?utf8=%E2%9C%93&q=unsubscribe&type= (1 hit in no test code but related with MQTT)

If my theory confirms (I may be wrong) it seems that unsubcription code in the library is dead code. As a consecuence, subscriptions are not correctly cleaned up when devices are deleted by API, leaving dirty stuff in CB.

fgalan avatar Feb 01 '18 18:02 fgalan

i can also add that when you delete a service with device=true no device is actually deleted contrary to what the API description states

chicco785 avatar Mar 04 '18 17:03 chicco785

i can also add that when you delete a service with device=true no device is actually deleted contrary to what the API description states

Only in sceanrios involving bidirectionality plugin? Or always?

In the second case, maybe it should be moved to an independent issue.

fgalan avatar Mar 05 '18 14:03 fgalan

i have to check

chicco785 avatar Mar 05 '18 14:03 chicco785

@fgalan sir I am looking in this issue. as we saw its an old issue , i really want to know it is good to go or not.

Sunny-NEC avatar Aug 10 '21 07:08 Sunny-NEC

@fgalan sir I am looking in this issue. as we saw its an old issue , i really want to know it is good to go or not.

The issue is old, but under my understanding it's still valid for working on it. That for your willingness!

fgalan avatar Aug 10 '21 13:08 fgalan

PR #1082

fgalan avatar Aug 26 '21 07:08 fgalan

remove the removeAllSubscriptions function but as the community said this is not the solution for this issue. so I am going to drop this issue .

Sunny-NEC avatar Feb 08 '22 04:02 Sunny-NEC

remove the removeAllSubscriptions function but as the community said this is not the solution for this issue. so I am going to drop this issue .

@Sunny-NEC I don't understand what you mean by "as the community sais this is not the solution". Who is "the community" in this context? Could you elaborate a little bit, please?

fgalan avatar Feb 08 '22 08:02 fgalan

@fgalan I am taking the reference https://github.com/telefonicaid/iotagent-node-lib/pull/1082#issuecomment-906161732 if their is any other approach for this issue please let me know :) .

Sunny-NEC avatar Feb 08 '22 08:02 Sunny-NEC

@fgalan I am taking the reference #1082 (comment) if their is any other approach for this issue please let me know :) .

Well, the solution is the one I describe in that comment you cite ;)

So the solution shouldn't be remove the unsubscription code in the library but using it properly in the user code (IOTA agents code) to clean up subscriptions when devices are deleted so no "zombie" subscription remains at CB after the deletion.

I think is pretty clear, but don't hesitate to ask if you don't understand something, please.

fgalan avatar Feb 09 '22 13:02 fgalan