web3/web3.js

timeout is not working with providers

Open

#6.178 aberto em 9 de jun. de 2023

Ver no GitHub
 (18 comments) (0 reactions) (1 assignee)TypeScript (5.078 forks)batch import
4.xBugDiscussionGood First Issue

Métricas do repositório

Stars
 (18.202 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

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

Guia do colaborador