undici icon indicating copy to clipboard operation
undici copied to clipboard

Uncaught TypeError: fetch failed. node:internal/deps/undici/undici:12345:11

Open yqz945 opened this issue 1 year ago • 1 comments

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

yqz945 avatar Mar 15 '24 02:03 yqz945

@ShogunPanda this might be due to happy eyeballs and some IPv6 misconfig on the network.

mcollina avatar Mar 18 '24 08:03 mcollina

Duplicate of #3410

Uzlopak avatar Aug 27 '24 18:08 Uzlopak