A Next.js 14 app on Vercel (Node 20.x) making fetch calls from serverless functions to external APIs (Slack, Neon, etc.) intermittently failed with TypeError: fetch failed ... cause: ConnectTimeoutError ... code: 'UNDERRCONNECT_TIMEOUT'. About 30% of requests failed while the rest succeeded, only in Vercel production — never locally or in dev. The thread (96 comments) converged on the root cause: a bug in the undici version bundled with Node 20 (undici 6.19, present in Node 20.18); the fix landed in undici 6.20.
Vercel: fetch from serverless function fails with "UND_ERR_CONNECT_TIMEOUT" on Node 20
The failures come from a buggy undici (6.19) bundled inside Node 20's fetch, not from Vercel's network. Confirmed workarounds: 1) downgrade the Vercel project to Node 18.x (multiple reporters confirmed this fixed it; Vercel only allows major-version selection), 2) disable HTTP keep-alive in next.config.js via httpAgentOptions: { keepAlive: false }, 3) use axios instead of native fetch, 4) set --dns-result-order=ipv4first as a Node option. The durable fix is a Node patch carrying undici 6.20+ — Node 22/23 lines picked it up via nodejs/node#55503. Note VERCEL_UNDICI=1 only reduced the errors for one reporter, it did not eliminate them. Source: https://github.com/vercel/vercel/issues/11692
Source: https://github.com/vercel/vercel/issues/11692