web3/web3.js

timeout is not working with providers

Open

#6178 opened on Jun 9, 2023

View on GitHub
 (18 comments) (0 reactions) (1 assignee)TypeScript (18,202 stars) (5,078 forks)batch import
4.xBugDiscussionGood First Issue

Description

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

Contributor guide