telefonicaid / telefonicaid/iotagent-node-lib

Bidirectional plugin doesn't perform unsubscription on device removal

Open
#576 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
62
Forks
90
Avg merge
2h 35m
Merged PRs (30d)
1

Description

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:

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

and nobody using in the IOTA UL agent:

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/services/ngsi/subscriptionService.js at unsubscribe() and lib/services/devices/deviceService.js at removeAllSubscriptions(). Trace device-removal callers and search the related agent repositories to verify whether cleanup is connected. Done means device deletion triggers the intended Context Broker unsubscription, with tests covering the cleanup path.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.