Websocket Provider "error" and "end" events not fired when client disconnects
As reported by @hfa0 in #3190 comment, 1.2.7 introduces a bug where "error" and "end" listeners directly attached to the Websocket provider aren't firing as expected on close.
Subscriptions and events do have their error handlers fired, and pending requests should also error correctly.
provider = new Web3.providers.WebsocketProvider(url);
provider.on('end', () => {
// not fired
});
provider.on('error', () => {
// not fired
});
provider.on('close', (event) => {
// event fired
})
contract.events[type]({ fromBlock }).on('error', (err) => {
// event fired
})
provider.disconnect(1012, 'restart');
The "close" event contains an object lots of information about what happened fwiw:
"type": "close",
"isTrusted": false,
"_yaeti": true,
"code": 1006,
"reason": "Connection dropped by remote peer.",
"wasClean": false,
... etc
Web3.js versions: 1.2.7, 1.2.7-rc.0
Re-opening for visibility. (Not sure how widely used the provider.on('error') pattern is and .on('close') is a reasonable work-around if a patch is a needed asap).
I got the same error on 1.2.7
Fixed in 1.2.8
this doesn't work again in 1.3.4 - 'end', 'error' and even 'close' never fire - only 'connect' does. Also, where is the documentation?? Available events description is absent altogether. It needs to be drastically improved. Including the available provider options. Right now there is just a usage example without any explanation of what e.g. "auto" or "keepalive" do and how they are (expected) to work exactly.
issue persist in "web3": "^1.8.1"