undici: fetch fail: cause: AggregateError [ETIMEDOUT]:
Bug Description
my code is typescript. I run it in two ways:
- use bun
- compile to js, and use node v21
when use bun run it, no error occurs; when use node run it, it occurs fetch failed extremely frequent
the request is an apollo graphql request. proxy is local http proxy:
https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
Logs & Screenshots
ApolloError: fetch failed
at new ApolloError (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/@apollo/client/errors/errors.cjs:33:28)
at /Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/@apollo/client/core/core.cjs:2017:78
at both (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/@apollo/client/utilities/utilities.cjs:1347:31)
at /Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/@apollo/client/utilities/utilities.cjs:1338:72
at new Promise (<anonymous>)
at Object.then (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/@apollo/client/utilities/utilities.cjs:1338:24)
at Object.error (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/@apollo/client/utilities/utilities.cjs:1349:49)
at notifySubscription (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/zen-observable/lib/Observable.js:140:18)
at onNotify (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/zen-observable/lib/Observable.js:179:3)
at SubscriptionObserver.error (/Users/guotie/guotie/product/ZUGGER/poolapi/node_modules/zen-observable/lib/Observable.js:240:7) {
graphQLErrors: [],
protocolErrors: [],
clientErrors: [],
networkError: TypeError: fetch failed
at node:internal/deps/undici/undici:12442:11
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:540:9)
at process.processTimers (node:internal/timers:514:7) {
cause: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1116:18)
at internalConnectMultiple (node:net:1184:5)
at Timeout.internalConnectMultipleTimeout (node:net:1707:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: 'ETIMEDOUT',
[errors]: [Array]
}
},
extraInfo: undefined
}
Environment
Mac M1 Sonoma 14.2
Nodejs v21
Additional context
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 14
- Comments: 30 (11 by maintainers)
Commits related to this issue
- fix(frontend): AggregateError `ETIMEDOUT` - https://github.com/nodejs/undici/issues/2777#issuecomment-2566924362 — committed to Aylie-Chou/congress-dashboard-monorepo by deleted user 2 years ago
I’ve been working on the same problem for 1 day. Some comments talk about connection, but I don’t think that’s the case, because I have a very good connection, and it’s not a device problem.
Here’s the solution:
check your ip dns configuration or clear your dns cache; make sure your router is serving a real dns server, or change your ip dns to target a real dns server.
The observation is that on my online server the code doesn’t throw this AggregateError [ETIMEDOUT] error, but on my local machine it always throws this error only when I’m at home on my local network.
Looking further, the main errors thrown are ETIMEDOUT and ENETUNREACH. This usually occurs when the DNS module is unable to resolve the IP address.
if the request got succesful once, it seems that the ip address in the log error can be the cached ones stored in your machine before.
My hypothesis is that when working under a network or router with a non-dns server, the node’s dns module is no longer able to evaluate the ip address and doesn’t use the cached one and sends errors.
I’ll check this out, but you have the solution. I changed my dns configuration in /etc/resolv.conf to 8.8.8.8 or 1.1.1.1. and everything’s back to normal!
@nodated
The issue for most of these errors is Node default --enable-network-family-autoselection at the detault 250ms being to short and causing a timeout. Network family selection resolves based on the network condition if request should go to IPv4 or IPv6 address.
Disabling IPv6 indeed will not cause above to kick in.
In my case, the issue was that
fetchcould not resolve the IPv6 address, even thoughcurlandwgetalways worked. Disabling IPv6 resolved the issue for me:sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1Maybe will also solved by #3707 by @metcoder95
@guotie @Uzlopak I have run into the same issue - only to recall that I have already resolved it, but did not remember the code.
https://github.com/nodejs/undici/issues/2990
On some networks (like e.g. mine today on a LTE tethered connection in a country far away from my database provider) the default
network-family-autoselection-attempt-timeout250 ms to resolve domain IP might not be enough and results in ETIMEDOUT.Doubling that time solves all issues for me:
export NODE_OPTIONS="--network-family-autoselection-attempt-timeout=500"It is addressed, the PR was also approved by you. Not sure how your merging process works.