web3/web3.js

timeout is not working with providers

Open

#6178 aperta il 9 giu 2023

Vedi su GitHub
 (18 commenti) (0 reazioni) (1 assegnatario)TypeScript (5078 fork)batch import
4.xBugDiscussionGood First Issue

Metriche repository

Star
 (18.202 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Web3 provider timeout is getting ignored . In my dapp I have set timeout to 5000 . web3.eth.getBlockNumber() doesn't throw even when public node takes more than 5s to respond .

Minimal example

var {Web3} = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("https://evm.confluxrpc.com", {timeout: 0 })); 
async function getNewBlock (){ 
    newBlock = await web3.eth.getBlockNumber();
    return newBlock
    
}
getNewBlock().then((nb)=>{ 
    console.log(" SHOULDN'T BE PRINTING THE BLOCK BUT IT IS: ",nb," block number")
})

Expected behavior

innerError: { code: -32000, message: 'failed after 0 retries: timeout' },

OUTPUT

SHOULDN'T BE PRINTING THE BLOCK BUT IT IS: 72889142n block number

Environment

Windows Node.js v19.0.0. web3 8.19.2

Guida contributor