Repository navigation
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
Reacted by Dillon Mulroy, Rocktim, Sukka, Imamuzzaki Abu Salam, Tapani Saarinen, 沈鸿飞, mizumotech, axome-vchangea, Muma, ReYuki and 5 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
mcollina commentedon Feb 18, 2024
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.
guotie commentedon Feb 18, 2024
repo is here: https://github.com/guotie/fetch-failed
I think the problem is timeout.
when the network is Ok, it rarely throw
fetch failed; when the network is busy, error occurs more frequent.smisra3 commentedon Mar 14, 2024
Facing a similar issue
ahmadxgani commentedon Apr 8, 2024
same issue, anyone know the solution?
ahmadxgani commentedon Apr 8, 2024
if the internet connectivity was the issue, then why curl always work and never throw timeout?
realyukii commentedon Apr 8, 2024
it seems this error only appear in certain environment or device? it's hard to reproduce but I think the bug really exists
someone already describe the same issue here too #2990
ahmadxgani commentedon Apr 8, 2024
or in certain host? I faced this issue when trying to fetch telegram api
ahmadxgani commentedon Apr 8, 2024
here's the endpoint that I try to fetch
metcoder95 commentedon Apr 9, 2024
Can you provide an
Minimum Reproducible Example to support you better?
realyukii commentedon Apr 10, 2024
I've provided the Minimum Reproducible Example on my Gist, as you suggested.
If you have a strong or reliable internet connection, consider simulating slow connectivity to see if the error replicates. After all, ETIMEDOUT errors are more likely to occur under limited bandwidth conditions.
Interestingly, while fetch sometimes throws this error, curl seems to be able to avoid it in this scenario.
metcoder95 commentedon Apr 10, 2024
Hmm, this does not seem like an
undicierror per se but rather a different way of handling connect timeouts.The errors shown by the example and the roots of the issue mostly to the initial TCP connection (including TLS), meaning that
undicitimed out before the server could finish the initial connect operation.You can attempt to extend the overall timeout while creating a custom
Agent(See https://undici.nodejs.org/#/docs/api/Client?id=parameter-clientoptions) and test if that solves the timeout issue, which seems related directly to the network conditions.As well, you can wrap it with the
RetryAgentto automatically retry upon this errors.realyukii commentedon Apr 10, 2024
in the docs it says:
why it close the connection too early if the default was 300 seconds? does the node fetch use undici differently in the internal?
btw, this is unrelated question: why I can't access undici directly (
require('undici')) if it was used in fetch implementation of node? is there a way to expose it, so I can use theRetryAgentclass without installing undici dependency?metcoder95 commentedon Apr 10, 2024
The timeouts you mention are applied directly at
httplevel, meanwhile thetimeoutI'm referring to, is linked to the TCP handshake; which by default is10s(lower than the body and headers).Sadly no, you'll need to install
undicito make use of theRetryAgent.realyukii commentedon Apr 11, 2024
Thanks for your assistance! It's confirmed that increasing the connection timeout resolved the issue in my scenario ^^
7 remaining items
metcoder95 commentedon Jan 14, 2025
I'd rather say that is not really an
undicinornode.jsproblem as it can be sorted out by extending the timeout for the DNS resolution; might be worth it to document thogregonarash commentedon Jan 15, 2025
@metcoder95 true. It could be debated if this is the right default in
node.js- under the same conditionscurlworks,fetchdoes not , but not really a bug.Either way I expect issues will continue to be opened in upstream repositories like
undici,nextjsfor fetch fail - AggregateError [ETIMEDOUT]. I replied to couple threads like that to boost visibility. I have also added pull request to add comment about this in the docs, but it seemed to have been removed recently.metcoder95 commentedon Jan 15, 2025
Do you have the PR at hand? Why was removed?
If seeking to extend the timeout, I'd suggest opening an issue in Node.js with the reference to the other issues you've opened and the feedback you've got to see where it lands.
For this issue, having the comment added into the documentation about high-latency networks should be ok.
gregonarash commentedon Jan 15, 2025
@metcoder95
I thought it was merged, but not sure what happened:
#3738
metcoder95 commentedon Jan 15, 2025
can you just address the recommendation there?
gregonarash commentedon Jan 15, 2025
It is addressed, the PR was also approved by you. Not sure how your merging process works.
nodated commentedon Feb 25, 2025
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=1gregonarash commentedon Feb 25, 2025
@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.
RnbWd commentedon Mar 31, 2025
export NODE_OPTIONS="--network-family-autoselection-attempt-timeout=500" worked for me. I have no idea what that option means, but I assume it's related to how far away the DNS lookup is
fix(frontend): AggregateError `ETIMEDOUT`
mehediwsit commentedon Jul 24, 2025
Thank you
ci(check_repository_health): workaround nodejs bug for selecting ipv4/v6
feat: SSR but need NODE_OPTIONS='--network-family-autoselection-attem…
Fix Node fetch hang against Apollo via IPv4-only undici dispatcher