-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetch times out in under 5 seconds #1531
Comments
Thanks for reporting! Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that. |
Hey!
|
Undici fails if your DNS is set to your router which in turn uses google DNS but if i sed the google DNS directly on my machine it would work, this shouldn't be happening i believe. |
Can you create a reproduction without using an external server? Something that we can run locally. |
I can give that a try but I believe that would just run as I believe that undici isn't able to resolve the webpage to an ip address which explains how a direct dns configuration resolved the issue. |
Can you try to replicate it with a external server and the dns set to your router?
|
I have a very similar setup, and there is no problem in contacting the discord API. Can you try running your script with |
Are you sure it's 5 seconds? Our default connect timeout is 10s? I suspect your dns lookup or ssl negotiation is taking more than 10s or something... |
A direct DNS to 8.8.8.8 works flawlessly on undici but a DNS pointing to the router fails. I will get you the timestamp in a few hours |
I don't think this is a undici problem. This works for axios probably because it has a longer (or no) timeout for establishing the connection. |
The timeout should be configurable with: import { fetch, setGlobalDispatcher, Agent } from 'undici'
setGlobalDispatcher(new Agent({ connect: { timeout: 60_000 } }) )
fetch(...) |
I am also getting |
I'm having the same issue. I'm using NET 56348: pipe false undefined
NET 56348: connect: find host discord.com
NET 56348: connect: dns options { family: undefined, hints: 32 }
NET 56348: _read
NET 56348: _read wait for connection
NET 56348: destroy
NET 56348: close
NET 56348: close handle
ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (/home/eduardo/proj/DescicloBot/bot_stable/node_modules/undici/lib/core/connect.js:131:24)
at /home/eduardo/proj/DescicloBot/bot_stable/node_modules/undici/lib/core/connect.js:78:46
at Immediate._onImmediate (/home/eduardo/proj/DescicloBot/bot_stable/node_modules/undici/lib/core/connect.js:119:9)
at processImmediate (node:internal/timers:471:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
NET 56348: emit close Is |
@mcollina maybe we should consider increasing the default timeout? |
That's not the problem. The problem is that all those folks have IPv6 misconfigured and we are missing Happy Eyeballs in Node.js nodejs/node#41625. Hopefully it will land before Node.js v18 goes LTS or shortly thereafter. |
ive gotten into this issues as well, i dont know which lines of code did its so heres all of it const fs = require('node:fs'); const axios = require('axios'); const https = require('https'); const data = JSON.stringify({ const options = { const error1 = process.env.INVALID_REQUESTED_URL const express = require('express'); const mongoose = require('mongoose'); const alert = process.env.COTENT_DOWN || "Sorry But the content on this page for this web server is currently down, please try again later" const port = process.env.PORT || 443 const prefix = '/' // then you may define it like so const commands = [ const rest = new REST({ version: '11' }).setToken('your token'); (async () => {
} catch (error) { client.on('ready', () => { client.on('interactionCreate', async interaction => { if (interaction.commandName == 'ping') { const server = http.createServer((req, res) => {
}); app.use( app.use(express.json()); app.post('localhost:443/host/app', (req, res) => { server.listen(port, () => { client.on("message", msg => { client.login('Your Token'); |
and also here the error ConnectTimeoutError: Connect Timeout Error |
i have same problem in undici.request() or undici.fetch().
But it only happens when i pass dispatcher field to options
when i dont pass dispatcher to options it works fine without any
But in my case i needed option update if i pass globally at top
app works much better |
Just wanted to make a note for anyone else that experiences this error Inspired by #1531 (comment) I found it is possible to configure the max connections limit (per host) using import { fetch, setGlobalDispatcher, Agent, Pool } from "undici";
setGlobalDispatcher(
new Agent({ factory: (origin) => new Pool(origin, { connections: 128 }) })
);
fetch(...) which alleviates the problem on Azure App Service |
hey, i've run into this issue and I don't understand why. how can i fix it? |
I think I am affected by this issue, too - I can't make any requests to hosts with an > await fetch('https://cloudflare.com');
Uncaught TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11118:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async REPL7:1:33 {
cause: ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (node:internal/deps/undici/undici:6625:28)
at node:internal/deps/undici/undici:6583:50
at Immediate._onImmediate (node:internal/deps/undici/undici:6614:13)
at process.processImmediate (node:internal/timers:471:21)
at process.topLevelDomainCallback (node:domain:161:15)
at process.callbackTrampoline (node:internal/async_hooks:128:24) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
} It works for services like GitHub, which refuse to implement IPv6 and only have > await fetch('https://github.com');
Response {
[Symbol(realm)]: null,
[Symbol(state)]: Proxy [
{
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 200,
timingInfo: [Object],
cacheState: '',
statusText: 'OK',
headersList: [HeadersList],
urlList: [Array],
body: [Object]
},
{ get: [Function: get], set: [Function: set] }
],
[Symbol(headers)]: HeadersList { /* ... */ }
} Is this expected? Can I do anything for the time being? |
You need to flip the setting in Node.js core:
Actually I think we can ship a new default here and enable https://nodejs.org/docs/latest-v18.x/api/net.html#socketconnectoptions-connectlistener. and enable happy eyeballs in Node v18. @ronag wdyt? |
Running into this with the official |
@bcomnes it's not a problem of DNS resolution but rather ipv6 connectivity. contact fly support. They had ipv6 issues in the past and they fixed them, so possibly it's on their side. |
Odd, I just deployed with EDIT: I believe this was a fly IPv6 connective issue that was resolved. |
This error happened to me while running nodemon without making any fetch request. My WiFi router emits at the same time a 5G and a 2.4G bands merged/mixed into one wireless network. Due to coming close to the router, my Mac auto-connected to the 5G and this UND_ERR_CONNECT_TIMEOUT error started showing. I turned off the VPN and it did not, but when I turned it on again, even with a different DNS the error showed up again. I manually disconnected from the wireless network and reconnected. The error does not show up any longer… |
In my case, switch node from 18 to 20 is solved |
This commit introduces the `force-ipv4` GitHub action to address connectivity issues caused by the lack of IPv6 support in GitHub runners. Details: - actions/runner#3138 - actions/runner-images#668 This change solves connection problems when Node's `fetch` API fails due to `UND_ERR_CONNECT_TIMEOUT` errors. Details: - actions/runner-images#9540 - actions/runner#3213 This action disables IPv6 at the system level, ensuring all outging requests use IPv4. Resolving connectivity issues when running external URL checks and Docker build checks. This solution is a temporary workaround until GitHub runners support IPv6 or Node `fetch` API has a working solution such as Happy Eyeball. Detais: - nodejs/node#41625 - nodejs/undici#1531
Here's my workaround (open-source and documented) that I hope that can help you too:
After days of research and trial/error, this is how I got this working:
Related commit introducing this fix: undergroundwires/privacy.sexy@52fadcd |
This solved it for me too |
Bug Description
When trying to fetch a URL a
fetch failed
error is thrown with the code ascode: '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
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.
The text was updated successfully, but these errors were encountered: