Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

HttpProvider promise doesn't resolve on invalid RPC endpoint. #2396

@kelsos

Description

@kelsos

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAddressing a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions