question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FallbackProvider not catch detectNetwork error

See original GitHub issue

Ethers Version

5.6.0

Search Terms

No response

Describe the Problem

the issue is regarding the fallback-provider. i have 3 providers configured and the quorum is set to 1. However, the query request (such as getBalance) will fail with only 1 JsonRpcProvider malfunction. As the quorum is set to 1, that’s not expected to happen.

After digging into the source code, i find the detectNetwork function is not catching the no network error. i have made changes to the original source code, and then my test passed.

below is the new code

  async detectNetwork(): Promise<Network> {
    const networks = await Promise.all(
      this.providerConfigs.map(async (c) => {
        try {
          return c.provider.getNetwork();
        } catch (error) {
          return null;
        }
      }),
    );
    return checkNetworks(networks as Array<Network>);
  }

also in checkNetworks, the check should continue in the for loop when no network is provided

   if (network == null) {
      continue;
    }

Code Snippet

the way i initiated a FallbackProvider


new FallbackProvider(
      [
        {
          provider: new ethers.providers.JsonRpcProvider(url1), 
          priority: 3,
          stallTimeout: 200,
          weight: 1,
        },
        {
          provider: new ethers.providers.JsonRpcProvider(url2), 
          priority: 1,
          stallTimeout: 200,
          weight: 1,
        },
        {
          provider: new ethers.providers.JsonRpcProvider(url3), 
          priority: 2,
          stallTimeout: 200,
          weight: 1,
        },
      ],
      1,
    );

Contract ABI

No response

Errors

No response

Environment

node.js (v12 or newer)

Environment (Other)

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
samholmescommented, Apr 11, 2022

@cliff0412 A PR would be super helpful IMO. I wouldn’t ask permission, but rather just contribute the PR and let the maintainers decide whether it’s worth including.

Do you have a link to your fork so I may evaluate your code-changes and fork from your fixed state until the change moves upstream?

0reactions
cliff0412commented, Aug 8, 2022

@ricmoo i have forked and made a pr. pls refer to https://github.com/ethers-io/ethers.js/pull/3247

Read more comments on GitHub >

github_iconTop Results From Across the Web

ZuulFallbackProvider not getting invoked - Stack Overflow
No specific error message from Zuul. The request just fails with 500 error, which would be the expected behavior if the fallback was...
Read more >
Transaction Details - Galileo POA Explorer
... new Error("empty");return!0}catch(e){}return!1}function d(t){"string"! ... detectNetwork()),e||F.throwError("no network detected" ...
Read more >
dist/ethers.esm.js - Renovate Bot Package Diff
+ catch (error) { ... The Cloudflare provider does not support eth_blockNumber, ... caught up to the FallbackProvider, before sending a request to...
Read more >
Providers - Ethers.js
It creates a FallbackProvider connected to as many backend services as possible. ... If no network is provided, homestead (i.e. mainnet) is used....
Read more >
Providers — ethers.js 4.0.0 documentation
If you are not running your own local Ethereum node, it is recommended that you ... This creates a FallbackProvider backed by multiple...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found