fetch fails with ETIMEOUT

I am learning node and in this tutorial's https://nodejs.org/en/learn/manipulating-files/reading-files-with-nodejs last sippet they are fetching a txt file from a url. However I keep getting this error
ganesh@LAPTOP-G6NM8GVN:~/repos/node-practice$ node app.js
Debugger attached.
TypeError: fetch failed
at node:internal/deps/undici/undici:13502:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async downloadFile (file:///home/ganesh/repos/node-practice/app.js:10:22)
at async file:///home/ganesh/repos/node-practice/app.js:44:3 {
[cause]: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1139:18)
at internalConnectMultiple (node:net:1215:5)
at Timeout.internalConnectMultipleTimeout (node:net:1739:5)
at listOnTimeout (node:internal/timers:596:11)
at process.processTimers (node:internal/timers:529:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
Error: fetch failed
ganesh@LAPTOP-G6NM8GVN:~/repos/node-practice$ node app.js
Debugger attached.
TypeError: fetch failed
at node:internal/deps/undici/undici:13502:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async downloadFile (file:///home/ganesh/repos/node-practice/app.js:10:22)
at async file:///home/ganesh/repos/node-practice/app.js:44:3 {
[cause]: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1139:18)
at internalConnectMultiple (node:net:1215:5)
at Timeout.internalConnectMultipleTimeout (node:net:1739:5)
at listOnTimeout (node:internal/timers:596:11)
at process.processTimers (node:internal/timers:529:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
Error: fetch failed
I searched a bit but All i can see is how to apply timeout to fetch. I'd be thankful if someone can point me to the right direction. if it matters I'm running node in WSL2 with ubuntu
1 Reply
Ganesh
GaneshOP2mo ago
okay I tried replacing the url with some other txt file url or png and it works but this url doesn't. I don't understand I can access the file by typing it in my browser so it should be public? Okay so apparantly the fetch failing wasn't the link issue at all. https://github.com/nodejs/undici/issues/2777 Something about default dns resolve time being 250 and that wasn't enough network-family-autoselection-attempt-timeout=500 made it work. I don't understand the intricacies and I don't care. This was such a goose chase ... I'm just leaving this here for the curious ones

Did you find this page helpful?