Web3.js: web3.shh.clearSubscriptions throws TypeError and fails

Created on 16 Mar 2018  路  3Comments  路  Source: ChainSafe/web3.js

Calling web3.shh.clearSubscriptions to clear subscriptions fail with a TypeError, with or without any active subscriptions.

System information

web3.js version: 1.0.0-beta.31
Browser Version: Chrome 64.0.3282.186
Commit hash : 956cdc54a851ce5c727f17b81a5d224ed0b92124

Expected behaviour

web3.shh.clearSubscriptions would execute with no error with or without an active subscription.

Actual behaviour

web3.shh.clearSubscriptions fails with a TypeError whether or not an active subscription exists.

TypeError: Cannot convert undefined or null to object

Steps to reproduce the behaviour

A gist was prepared to demonstrate the two failure cases.

See https://gist.github.com/dhl/b463ce9a6bd09e87fe74c992d7958d53

Backtrace

````
web3-1.0.0-beta.31_clearSubscriptions_bug_demo.html:22 TypeError: Cannot convert undefined or null to object
at Function.keys ()
at a.u.clearSubscriptions (web3.min.js:1)
at web3-1.0.0-beta.31_clearSubscriptions_bug_demo.html:19
(anonymous) @ web3-1.0.0-beta.31_clearSubscriptions_bug_demo.html:22

````

bug

Most helpful comment

I worked around this issue by setting the subscription instance to an object parameter and then I have access to the unsubscribe method.

Ethereum.blockSubscription = web3Socket.eth.subscribe('newBlockHeaders', function (error, sync) {..}

then called it

Ethereum.blockSubscription.unsubscribe(function (error, success) {..}

All 3 comments

I worked around this issue by setting the subscription instance to an object parameter and then I have access to the unsubscribe method.

Ethereum.blockSubscription = web3Socket.eth.subscribe('newBlockHeaders', function (error, sync) {..}

then called it

Ethereum.blockSubscription.unsubscribe(function (error, success) {..}

I submitted a pull request with for the shh unsubscribe function. We use that to circumvent the bug you are describing.

var subscription = web3.shh.subscribe("messages", {
   symKeyID: ...,
   topics: ...
})
console.log({"subscription": subscription})
web3.shh.unsubscribe(subscription.id)

This will be fixed within the next release. (PR #2000)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ragnu picture ragnu  路  3Comments

princesinha19 picture princesinha19  路  3Comments

sundbry picture sundbry  路  3Comments

connectdotz picture connectdotz  路  3Comments

TinyWJL picture TinyWJL  路  3Comments