Skip to content

Respect timeout passed to fetch #16682

Closed

Description

@jhwz

What version of Bun is running?

1.2.0+b0c5a7655

What platform is your computer?

Darwin 24.2.0 arm64 arm

What steps can reproduce the bug?

From #5930 (and #6217) it seems Bun hardcodes a fetch timeout to 5 minutes (which seems like a sensible default).

When I pass a longer timeout to fetch, e.g.:

fetch(url, {
      signal: AbortSignal.timeout(1000 * 60 * 60), // 1 hour
})

after 5 minutes bun throws

FetchError: The request failed and the interceptors did not return an alternative response
      at new FetchError (...)

AbortError: The operation timed out
 code: "ABORT_ERR"

and doesn't respect the longer timeout.

What is the expected behavior?

If a signal is given which is longer than the default, it should be respected

What do you see instead?

No response

Additional information

No response

Activity

  1. RiskyMH commented on Jan 24, 2025

    @RiskyMH
    Contributor

    Related to #13126 and #13302 which are closed but from my tests are still broken.

    Your specific is longer though, but just out of curiosity does it let you set lower then 5mins?

  2. Jarred-Sumner commented on Jan 24, 2025

    @Jarred-Sumner
    Collaborator

    This is happening because the timeout option in fetch doesn't know anything about AbortSignal.timeout

    We can fix it. It won't be 100% robust.

  3. themockingjet commented on Mar 5, 2025

    @themockingjet

    with 1.2.4 AbortSignal.timeout only works with 6 milliseconds settings, higher than that it floats

    // signal: AbortSignal.timeout(6)
    The operation timed out.
    [6.76ms] fetch
    
    // signal: AbortSignal.timeout(7)
    The operation timed out.
    [130.29s] fetch
    
  4. AkritW commented on Apr 12, 2025

    @AkritW

    This is happening because the timeout option in fetch doesn't know anything about AbortSignal.timeout

    We can fix it. It won't be 100% robust.

    I tested the timeout option in Bun by setting it to false. It is working.

    However, the documentation and typescript also has nothing to say about the timeout option being there.

  5. AkritW commented on Apr 20, 2025

    @AkritW

    Here is the current fix.

    fetch(url, {
          signal: AbortSignal.timeout(1000 * 60 * 60), // 1 hour
          // @ts-ignore
          timeout: false
    })

    Do note that typescript will scream at you since typescript doesn't know that the fetch have a parameter of timeout. You can suppress it using @ts-ignore or something similar.

  6. orange-GuandeLi commented on Aug 4, 2025

    @orange-GuandeLi

    Hope it can be fixed soon

  7. arthurvanl commented on Aug 20, 2025

    @arthurvanl
    Contributor

    I am waiting for this to be fixed since #13302
    But apparently that issue was closed for an unknown reason.

    I tried again but still seems not to work. My approach:

    console.log('oke');
    
    // DOES NOT WORK
    await fetch('https://devplesk.mintyserver.nl/a/a/a/a/a', {
        signal: AbortSignal.timeout(1000), 
        timeout: false
    })
    
    // WORKS without `timeout` prop
    // await fetch('https://tools.arthurvanl.nl/api/v1/delay/time?duration=6000', {
    //     signal: AbortSignal.timeout(1000), 
    //     // timeout: false
    // })
    console.log('oke')
  8. remorses commented on Oct 1, 2025

    @remorses
    Contributor

    Bun should just disable the timeout by default. It causes more problems than benefits

  9. damassi commented on Oct 30, 2025

    @damassi

    This took a very long time to track down due to missing stack traces or any info other than a TimeoutError. Thank you @AkritW for posting your solution 🙏

  10. 8 remaining items

  11. added a commit that references this issue on Jul 8, 2026
    3353737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneeds investigateNeeds to be investigated to find the root causeweb:fetch

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions