Web3.js: HttpProvider promise doesn't resolve on invalid RPC endpoint.

Created on 20 Feb 2019  路  1Comment  路  Source: ChainSafe/web3.js

All issues which aren't created with this template will get immediately closed.

This happens on an Angular 7 project, I am not sure if this issue also affects other frameworks or if it is some combination with the dependencies that Angular pulls.

After some debugging (that was made harder due to zone.js), I found out that when a net::ERR_NAME_NOT_RESOLVED or an net::ERR_CONNECTION_REFUSED error will happen
request.onreadystatechange will get called with request.readyState === 4 && request.status === 0.
Since there is no handling of this case the promise will not resolve at all.

https://github.com/ethereum/web3.js/blob/89ee348a9758362e994ef2d8625f8aef46c61b91/packages/web3-providers/src/providers/HttpProvider.js#L142

Expected behavior

Promise should reject when the connection is refused or DNS fails to resolve.

Actual behavior

The promise never resolves/rejects.

Steps to reproduce the behavior

  1. Set an invalid rpc endpoint url on the HttpProvider. It can be either an url of of something that is not an rpc endpoint or and invalid url that dns cannot resolve.
  2. Attempt to get the chain id await this.web3.eth.net.getId();

Error Logs

Versions

[NPM, Node, Web3.js, OS, device...]

  • npm: '6.4.1'
  • node: v10.13.0
  • web3.js: 1.0.0-beta.46

Chrome and Firefox (Linux)

bug

Most helpful comment

Thanks for creating this issue! I will check, fix and release it asap.

>All comments

Thanks for creating this issue! I will check, fix and release it asap.

Was this page helpful?
0 / 5 - 0 ratings