raidensan
raidensan

Reputation: 1139

Timeout when communicating with Web3 Provider

Background

I am trying to investigate and solve problems with a containerized NodeJS web service app that communicates with Avalanche Test Network (https://api.avax-test.network/ext/bc/C/rpc) in order to Mint NFTs.

//...
provider = new HDWalletProvider({
    privateKeys: [walletPrivateKey],
    providerOrUrl: "https://api.avax-test.network/ext/bc/C/rpc",
    pollingInterval: 4000,
});

const myContract = Contract(Contract_NFT);
myContract.setProvider(provider);

const _instance = await myContract.at(process.env.CONTRACT_NFT_ADDRESS);

_instance.mint(provider.getAddress(), mintURL, { from: provider.getAddress() })
//...

Note: I am not the developer of app.

Issue

After starting the container, first request completes successfully. However subsequent requests fail with code: -32603 message: 'ETIMEDOUT' error

at new NodeError (node:internal/errors:387:5)
at Web3ProviderEngine.emit (node:events:502:17)
at /app/node_modules/web3-provider-engine/index.js:54:14
at afterRequest (/app/node_modules/web3-provider-engine/index.js:148:21)
at /app/node_modules/web3-provider-engine/index.js:174:21
at /app/node_modules/web3-provider-engine/index.js:232:9
at /app/node_modules/async/internal/once.js:12:16
at replenish (/app/node_modules/async/internal/eachOfLimit.js:61:25)
at /app/node_modules/async/internal/eachOfLimit.js:71:9
at eachLimit (/app/node_modules/async/eachLimit.js:43:36)
at /app/node_modules/async/internal/doLimit.js:9:16
at end (/app/node_modules/web3-provider-engine/index.js:211:5)
at Request._callback (/app/node_modules/web3-provider-engine/subproviders/rpc.js:36:21)
at self.callback (/app/node_modules/request/request.js:185:22)
at Request.emit (node:events:513:28)
at Timeout.<anonymous> (/app/node_modules/request/request.js:851:16)

Error: PollingBlockTracker - encountered an error while attempting to update latest block:
undefined
    at PollingBlockTracker._performSync (/app/node_modules/eth-block-tracker/src/polling.js:51:24)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

When the app is used outside a container and directly on server OS, all requests successfully complete.

What I have tried

I tried searching the internet forums and boards. Similar issue is mentioned in some posts but suggested solution is to tweak Timeout/Interval values which did not help with my issue and still got the error.

I tried using the same NodeJS and NPM versions installed on server OS. Also tried using different versions of NodeJS( 14.XX, 16.XX). Still got the same error.

Also I have tried changing and configuring Docker network( different type of network driver, different IPAM config, passing extra hosts etc.). Still got the same error.

I have confirmed that mentioned URL is accessible from inside container using ping, nc and dig tools. Also have confirmed that successful HTTPS connection is being established.

Questions

What is causing this behavior?

What I can do to reliably use this app inside container?

Have I missed something?

Upvotes: 1

Views: 456

Answers (0)

Related Questions