undici
undici copied to clipboard
Uncaught TypeError: fetch failed. node:internal/deps/undici/undici:12345:11
Bug Description
node fetch can't not connect openai api endpoint. The following error occurred, and I think it's ok about one month ago. Uncaught TypeError: fetch failed at node:internal/deps/undici/undici:12345:11 node v18.*, v20.11.1
Reproducible By
PS C:\Users\Lenovo\Desktop> node
Welcome to Node.js v20.11.1.
Type ".help" for more information.
> await fetch('https://api.openai.com/v1/chat/completions')
Uncaught TypeError: fetch failed
at node:internal/deps/undici/undici:12345:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async REPL1:1:33 {
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:7478:37)
at process.processImmediate (node:internal/timers:478:21)
at process.topLevelDomainCallback (node:domain:160:15)
at process.callbackTrampoline (node:internal/async_hooks:128:24) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
Expected Behavior
The openai http api can be invoked normally
Logs & Screenshots
Uncaught TypeError: fetch failed at node:internal/deps/undici/undici:12345:11 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async REPL1:1:33 { 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:7478:37) at process.processImmediate (node:internal/timers:478:21) at process.topLevelDomainCallback (node:domain:160:15) at process.callbackTrampoline (node:internal/async_hooks:128:24) { code: 'UND_ERR_CONNECT_TIMEOUT' } }
Environment
nodejs version is : 20.11.1 os is: Microsoft Windows NT 10.0.22631.0 (Win11)
Additional context
I thought it's not a network issue. The browser is ok, and openai python sdk woks fine at the same time. google has same problem.
PS C:\Users\Lenovo\Desktop> node .\test.js
URL: https://www.google.com
node:internal/deps/undici/undici:12345
Error.captureStackTrace(err, this);
^
TypeError: fetch failed
at node:internal/deps/undici/undici:12345:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async run (C:\Users\Lenovo\Desktop\test.js:3:15) {
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:7478:37)
at process.processImmediate (node:internal/timers:478:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
Node.js v20.11.1
Github is ok.
PS C:\Users\Lenovo\Desktop> node .\test.js
URL: https://www.github.com
200
@ShogunPanda this might be due to happy eyeballs and some IPv6 misconfig on the network.
Duplicate of #3410