Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket Provider "error" and "end" events not fired when client disconnects #3485

Closed
cgewecke opened this issue Apr 26, 2020 · 5 comments · Fixed by #3486
Closed

Websocket Provider "error" and "end" events not fired when client disconnects #3485

cgewecke opened this issue Apr 26, 2020 · 5 comments · Fixed by #3486
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects

Comments

@cgewecke
Copy link
Collaborator

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

@cgewecke cgewecke added Bug Addressing a bug 1.x 1.0 related issues labels Apr 26, 2020
@cgewecke cgewecke added this to In progress in v1.2.8 Apr 26, 2020
@cgewecke
Copy link
Collaborator Author

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).

@cgewecke cgewecke reopened this Apr 27, 2020
@cgewecke cgewecke moved this from In progress to Done in v1.2.8 Apr 27, 2020
@maxprof
Copy link

maxprof commented May 3, 2020

I got the same error on 1.2.7

@ryanio ryanio mentioned this issue May 8, 2020
13 tasks
@cgewecke
Copy link
Collaborator Author

Fixed in 1.2.8

@jamboj
Copy link

jamboj commented Feb 27, 2021

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.

@emurmotol
Copy link

issue persist in "web3": "^1.8.1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
No open projects
v1.2.8
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants