web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.15k stars 4.9k forks source link

Add retry mechanism in HttpProvider #5593

Open fzn0x opened 1 year ago

fzn0x commented 1 year ago

Is there an existing issue for this?

Feature Request

Add retry mechanism for HTTP Provider.

Use Cases

Proxy agent can be flaky, I'm using https-proxy-agent sometimes it can be connected or not, can we add retry mechanism for http provider so every errors will be retried? currently I'm using p-retry in charge.

const web3 = new Web3(
  new Web3.providers.HttpProvider("https://bsc-dataseed1.binance.org:443", {
    agent: {
      https: HttpsProxyAgent(
        "http://auth@host:port"
      ),
    },
  })
);

web3.eth.net
  .isListening()
  .then(() => console.log("Provider is connected")) // sometimes binance accept the proxy IP
  .catch((err) => console.log("Wow. Something went wrong: " + err)); // sometimes not

My country internet is currently ban the provider. So proxy did help me.

Implementation Ideas

I would prefer in Web3.providers.HttpProvider options.

Feature Examples/References

This feature is available in web3.py.

Are you willing to implement this feature?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

alFReD-NSH commented 1 year ago

With web3 1.x, we can use fetch-retry to wrap global fetch, but with 4.x it's not possible out of the box. It would be nice if we could provide the fetch implementation to HttpProvider or have it contain something like fetch-retry.