telefonicaid / telefonicaid/iotagent-node-lib
Bidirectional plugin doesn't perform unsubscription on device removal
Nobody has claimed this yet.
- 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:
- 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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