nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.44k stars 276 forks source link

Fetch AbortController bug #4291

Closed aitimate closed 6 days ago

aitimate commented 8 months ago

URL:

https://nodejs.org/en

Browser Name:

nodejs

Browser Version:

nodejs

Operating System:

Windows 11 Pro, 22H2, 22621.2506

How to reproduce the issue:

;(async () => {

    for (let i = 0; i < 10; i++) {
        await t2();
    }
})()

async function t2() {
    console.time("---")
    let a
    try {
        const controller = new AbortController()
        setTimeout(() => controller.abort(), 3000)
        //  this url will take 10 seconds about
        a = await fetch("https://http-testnet.hecochain.com", {
            method: "POST",
            headers: {"Content-Type": "application/json", "accept": "application/json"},
            signal: controller.signal,
            body: JSON.stringify({
                "id": 1,
                "jsonrpc": "2.0",
                "method": "eth_blockNumber",
            }),
        })
    } catch (e) {

    }
    console.timeEnd("---")
    console.log(a)
}

async function t1() {
    console.time("---")
    let a
    try {
        a = await Promise.race([
            await new Promise(resolve => setTimeout(resolve, 3000)),
            fetch("https://http-testnet.hecochain.com", {
                method: "POST",
                headers: {"Content-Type": "application/json", "accept": "application/json"},
                body: JSON.stringify({
                    "id": 1,
                    "jsonrpc": "2.0",
                    "method": "eth_blockNumber",
                }),
            })
        ])
    } catch (e) {

    }
    console.timeEnd("---")
    console.log(a)
}

if timeout = 1000, everything is good, but 3000 not: image

github-actions[bot] commented 1 month ago

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] commented 6 days ago

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.