question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetch times out in under 5 seconds

See original GitHub issue

Bug Description

When trying to fetch a URL a fetch failed error is thrown with the code as code: ‘UND_ERR_CONNECT_TIMEOUT’ , This error is thrown at a request that barely takes 5 - 6 seconds to complete and other HTTP clients like axios and curl perform flawlessly on the same server

Reproducible By

Fetch any discord API url

Expected Behavior

The fetch should complete which is well below the 120s timeout

Logs & Screenshots

/home/arnav/Documents/tej.js/node_modules/undici/lib/fetch/index.js:197
        Object.assign(new TypeError('fetch failed'), { cause: response.error })
                      ^
TypeError: fetch failed
    at Object.processResponse (/home/arnav/Documents/tej.js/node_modules/undici/lib/fetch/index.js:197:23)
    at /home/arnav/Documents/tej.js/node_modules/undici/lib/fetch/index.js:930:38
    at node:internal/process/task_queues:141:7
    at AsyncResource.runInAsyncScope (node:async_hooks:201:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at Timeout.onConnectTimeout [as _onTimeout] (/home/arnav/Documents/tej.js/node_modules/undici/lib/core/connect.js:108:24)
      at listOnTimeout (node:internal/timers:561:11)
      at processTimers (node:internal/timers:502:7) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}

Environment

Gentoo, Node v17.6.0

Additional context

Happen on every discord API url and used to work some time back but suddenly just fails everywhere.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
SebastianZimmercommented, Aug 29, 2022

I am also getting UND_ERR_CONNECT_TIMEOUT after ~5 secs when IPv6 is not configured or working properly. With curl, Chrome and other clients, it still works via IPv4. This seems to be because Node does not implement Happy Eyeballs. There is already an issue for this: https://github.com/nodejs/node/issues/41625

1reaction
mcollinacommented, Oct 8, 2022

That’s not the problem. The problem is that all those folks have IPv6 misconfigured and we are missing Happy Eyeballs in Node.js https://github.com/nodejs/node/issues/41625. Hopefully it will land before Node.js v18 goes LTS or shortly thereafter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Timeout a fetch() Request - Dmitri Pavlutin
Users are OK to wait up to 8 seconds for simple requests to complete. That's why you need to set a timeout on...
Read more >
Fetch API request timeout? - javascript - Stack Overflow
I want to know what is the default timeout for this? and how can we set it to a particular value like 3...
Read more >
Quickie fetch timeout | Ben Ilegbodu
Libraries like axios provide lots of utilities for making HTTP requests, including timing out long-running requests. I've always used the native ...
Read more >
How to Set Timeout with the JavaScript Fetch API using ...
Use the setTimeout function to trigger the abort method after a specified time(convert to seconds by multiplying by 1000) and returns the ...
Read more >
A Complete Guide to Timeouts in Node.js - Better Stack
The above example sets the server timeout to 5 seconds so that inactive ... In Node.js, no default timeout is set for fetch()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found