-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
NextJS 14 returns fetch failed with UND_ERR_CONNECT_TIMEOUT error on serverless function #66373
Comments
This is most likely an Undici error. Can you try to collect more data about the endpoints that are failing? |
Hey @icyJoseph I only have these 2 APIs mentioned to test at the moment. |
Hi, well, it's not a Next.js thing, rather Node.js' fetch implementation uses undici at its core. For a world pre- Node 18 (17 really) Next js did a polyfill with node-fetch, to provide server side fetch, but since Node.js adopted fetch natively, Next.js just doesn't have to anymore. |
Maybe you can do an experiment. Does it also fail, if you create a node script, or just open the Node repl, and try to make a fetch request from there? |
I'm pretty sure this issue doesn't happen on local environments, only on live servers but I'll be testing on pure node soon. I also found these 2 related issues? |
This comment has been minimized.
This comment has been minimized.
Yeah I'm on that discussion as well. For me though it only happens in production, not local. |
|
Facing same issue in my project using nextjs 14. |
Facing the same problem with Nextjs 14.2.3 and node 20 under comporate http_proxy network. In build time, Nextjs is trying to fetch some cloudflare addresses [cause]: ConnectTimeoutError: Connect Timeout Error (attempted addresses: 104.16.24.34:443, 104.16.28.34:443, 104.16.26.34:443, 104.16.2.35:443, 104.16.0.35:443, 104.16.27.34:443, 104.16.31.34:443, 104.16.1.35:443, 104.16.30.34:443, 104.16.25.34:443, 104.16.29.34:443, 104.16.3.35:443) |
Same problem here. All day yesterday, we were getting UND_ERR_CONNECT_TIMEOUT errors only on Vercel's production build attempts. It was working when built locally. We're still on Next13. However, at 4:30 am, I tried to build it again in production, and everything worked fine. This is weird. We may still encounter this issue in future builds. Hoping for someone to find a fix for this. I'll also continue to observe. Err log:
|
Alright, this suggestion nodejs/undici#1531 (comment) might be the fix for UND_ERR_CONNECT_TIMEOUT error. After some additional research and debugging, I tried using |
Thanks. So what can I do in order to eliminate this issue? |
@ornakash, I just included Note that setting |
Thanks! it looks like it drastically reduced the times this happens. I hope they'll understand why it happens so we won't get even 6 errors |
To see which connectivity the DNS is using for your request, try using: dns.lookup('example.com', { all: true }, (err, addresses) => {
console.log({ addresses, err });
}); (Replace example.com with the DNS where you received the 6 errors.) The logs should show something like: {
addresses: [
{ address: '93.184.215.14', family: 4 },
{ address: '2606:2800:21f:cb07:6820:80da:af6b:8b2c', family: 6 }
],
err: null
} |
Linking my resolution here if it helps someone else vercel/vercel#11692 (comment) |
Same started happening in our project; 5% of requests on Vercel fail due to timeout. Locally they error out with Tried setting Running Next 14.0.4 and Node 18.x |
I am also getting a bunch of undici errors as well recently. These are the 3 main ones "next": "^14.2.3", I also tried setting vercel env variable: NODE_OPTIONS=--dns-result-order=ipv4first but it has not solved the issue
|
I am also facing this issue when calling API functions from Zapier:
|
I am also facing the same issue when trying to execute SQL using libsql client (Turso): There has been an error while retrieving the database type.
|
Just give my data point as well, but in this isn't a serverless, just a regular next workload. It works well when I was using these versions:
But now I am. using next
|
Hi folks - just want to crosspost a response from a message shared from someone on the Vercel infra team: vercel/vercel#11692 (comment) If you're receiving these Undici timeout errors and you're deploying with Vercel, you'll find that information helpful. If you experience it with other providers, you will likely need to wait Undici is updated in Node to include the version with the fixes. Here's the corresponding issue on the Undici side: nodejs/undici#3410 I'll be closing this as it's not currently actionable by the Next.js team. |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/gifted-shirley-mzlvgy?file=%2Fapp%2Fapi%2Froute.js%3A1%2C1-39%2C1
To Reproduce
Systems:
Full error message:
Unhandled Rejection: TypeError: fetch failed at node:internal/deps/undici/undici:12345:11 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { cause: ConnectTimeoutError: Connect Timeout Error at onConnectTimeout (node:internal/deps/undici/undici:7492:28) at node:internal/deps/undici/undici:7448:50 at Immediate._onImmediate (node:internal/deps/undici/undici:7480:13) at process.processImmediate (node:internal/timers:478:21) at process.callbackTrampoline (node:internal/async_hooks:130:17) { code: 'UND_ERR_CONNECT_TIMEOUT' } } Node.js process exited with exit status: 128. The logs above can help with debugging the issue.
Current vs. Expected behavior
Currently some external API calls from a serverless function are returning unhandled fetch errors.
Expected behaviour is no errors being returned and API call succeeding.
Provide environment information
Which area(s) are affected? (Select all that apply)
Module Resolution, Pages Router, Runtime
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
Additional information about the issue and more cases can be found at this discussion:
#57384
The text was updated successfully, but these errors were encountered: