Calling web3.shh.clearSubscriptions to clear subscriptions fail with a TypeError, with or without any active subscriptions.
web3.js version: 1.0.0-beta.31
Browser Version: Chrome 64.0.3282.186
Commit hash : 956cdc54a851ce5c727f17b81a5d224ed0b92124
web3.shh.clearSubscriptions would execute with no error with or without an active subscription.
web3.shh.clearSubscriptions fails with a TypeError whether or not an active subscription exists.
TypeError: Cannot convert undefined or null to object
A gist was prepared to demonstrate the two failure cases.
See https://gist.github.com/dhl/b463ce9a6bd09e87fe74c992d7958d53
````
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
````
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)
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.
then called it