From 1616d2f74b0b4fbf4c2c62fd9e713f9e941cc980 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 21 May 2020 11:04:15 -0700 Subject: [PATCH 1/3] Add failing test for eth.clearSubscriptions --- test/eth.subscribe.ganache.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/eth.subscribe.ganache.js b/test/eth.subscribe.ganache.js index bd2579d3ac2..67167486152 100644 --- a/test/eth.subscribe.ganache.js +++ b/test/eth.subscribe.ganache.js @@ -54,6 +54,15 @@ describe('subscription connect/reconnect', function () { }); }); + it('clearSubscriptions', async function() { + web3.eth.subscribe('newBlockHeaders'); + await waitSeconds(1); // Sub need a little time to set up + + assert.equal(1, web3.eth._requestManager.subscriptions.size); + web3.eth.clearSubscriptions(); + assert.equal(0, web3.eth._requestManager.subscriptions.size); + }); + it('resubscribes to an existing subscription', function (done) { this.timeout(5000); From 997f254334db75a361112b80ecd1e7e7736e8828 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 21 May 2020 11:38:12 -0700 Subject: [PATCH 2/3] Bind clearSubscriptions to RequestManager in web3.eth scope --- packages/web3-eth/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-eth/src/index.js b/packages/web3-eth/src/index.js index e42ed09f006..159b49547d4 100644 --- a/packages/web3-eth/src/index.js +++ b/packages/web3-eth/src/index.js @@ -265,7 +265,7 @@ var Eth = function Eth() { }); - this.clearSubscriptions = _this._requestManager.clearSubscriptions; + this.clearSubscriptions = _this._requestManager.clearSubscriptions.bind(_this._requestManager); // add net this.net = new Net(this); From 6e74e29c067749ab6bc6cdfa951dc686b3e8b89a Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 21 May 2020 11:40:44 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b8f01789c4..0392c16b587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -210,3 +210,5 @@ Released with 1.0.0-beta.37 code base. ### Changed ### Fixed + +- Fix size property de-referencing crash when calling web3.eth.clearSubscriptions (#3527)