'Working with HDWalletProvider in NodeJS, getting Unhandled error. ({ code: -32000, message: 'header not found' })

I have a NodeJS web3 app, reading PancakeSwap contracts. I get the odd intermittent error mostly:

 Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({ code: -32000,
 message: 'header not found' })
     at new NodeError (node:internal/errors:371:5)
     at Web3ProviderEngine.emit (node:events:379:17)
     at ...\web3-provider-engine\index.js:54:14
     at afterRequest (...\web3-provider-engine\index.js:148:21)
     at ...\web3-provider-engine\index.js:174:21
     at ...\web3-provider-engine\index.js:232:9
     at ...\async\internal\once.js:12:16
     at replenish (...\async\internal\eachOfLimit.js:61:25)
     at ...\async\internal\eachOfLimit.js:71:9
     at eachLimit (...\async\eachLimit.js:43:36)
     at ...\async\internal\doLimit.js:9:16
     at end (...\node_modules\web3-provider-engine\index.js:211:5)
     at Request._callback (...\node_modules\web3-provider-engine\subproviders\rpc.js:70:28)
     at Request.self.callback (...\request\request.js:185:22)
     at Request.emit (node:events:390:28)
     at Request.<anonymous> (...\request\request.js:1154:10) {  
 code: 'ERR_UNHANDLED_ERROR',   context: { code: -32000, message:
 'header not found' }

Checking the line:

 at Request.self.callback (...\request\request.js:185:22)

from the error list it seems that it's failing a double callback check in request.js

Generally it works quite well, and yesterday, happy with the performance, I shut things down and went to bed.

This morning though I set down to work and every 2 or 3 minutes I get the errors indicated.

I haven't found anything of significance on internet. The error seems quite "generic" and doesn't really help in isolating the problem. Debugging, it seems it happens randomly, that is, the actual call producing the error is not always the same.

I wonder if it might have something to do with internet, as there have been no changes to code since it was working and when it started with the errors.

The question really is "What would 'header not found' mean in a web3 context for calls like

exchangeAddress = await pancakeFactoryContract.methods.getPair(inputTokenAddress, outputTokenAddress).call()

The errors are random, It usually works for hours at a time, and just recently won't go more than a few minutes.

A speed test gives me 20Mbsec up and down, which is actually good for where I live. It has worked better for slower speeds.

NOTE: After more detailed debugging, I went through the Error list, finding the actual point of error in:

...\web3-provider-engine\index.js:54:14

where an error event was emitted for lack of header in one of the RPC responses. I temprarily fixed the problem removing the event emission (and adding a console.log of the problem.)

It's a temprary fix, permitting the program to carry on without undue problem, missing perhaps the odd response that has a corrupted header, which for the moment causes less problem than the program stopping.

Since I had not experienced problems before this, I expect that the BSC RPC is acting up temporarily.. although changing RPC hosts didn't seem to have any effect previously.

Maybe it's confused by the market LOL.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source