computer/개발

[BE] TypeError: fetch failed at node:internal/deps/undici/undici

ketrewq 2025. 10. 17. 22:38

setTimeout켜놓고 import node-fetch한다음 fetch를 썼는데 FetchError가 나길래 그냥 fetch를 썻는데 이번엔 본문 제목같은 에러가 남 

 

처음에 의심한거: 타임아웃? DNS? SSL?

다 아님. 심지어 다른 서버에서 요청하면 빠릿하게 잘 돌아옴. 

그리고 20번쯤 요청하면 한번은 잘 작동함. 

 

 

 

 

뭐지? 어딘가에서 시간싸움 또는 레이스컨디션이 나고 있다. 

지독한 로되리안에 갇혔는데 검색해보니까 그냥 노드문제였음 

 

 

https://github.com/nodejs/node/issues/54359

 

Happy eyeballs implementation times out prematurely · Issue #54359 · nodejs/node

Version v20.12.2 Platform Linux 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux Subsystem No response What steps will reproduce the bug? In an IPv4-only environment: NODE_DEB...

github.com

 

 

node 20에서는 autoSelectFamily 옵션이 디폴트로 켜져있는데 이는 Happy Eyeballs 로직을 "loose" 하게 구현함 

 

 

https://en.wikipedia.org/wiki/Happy_Eyeballs

 

Happy Eyeballs - Wikipedia

From Wikipedia, the free encyclopedia Algorithm for applications supporting both Internet protocol versions 4 and 6 Happy Eyeballs (also called Fast Fallback) is an algorithm published by the IETF that makes dual-stack applications (those that understand b

en.wikipedia.org

 

 

이게 뭐냐면 연결 될때까지 IPv6 IPv4다해보는거임 

 

듀얼스택인 내 서버 <-> 웹훅이 잇다고 해보자 

 

1. 가져온 첫번째 IPv6 (AAAA) 를 먼저 연결시도함 -> 안됨 

2. 가져온 첫번째 IPv4 (A)시도함 -> 안됨 

3. 그다음에 두번째 AAAA를 시도함 

(생략)

 

근데 여기서 ISP가 IPv6를 지원안하면? 

 

1. undici에서는 ipv4 ipv6 연결 타임아웃을 둘 다 250ms로 잡아놓고 잇음 이는 수정 불가 

2. DNS resolve 할때 DNS에서 A를 먼저 줌 

2. 근데 내 웹훅서버가 내 안방에 잇겟음? 서버가 멀어서(또는 다른 이유에서든머든) 타임아웃이 남 

3. 어 뭐지? 이게 안되면 다음 AAAA 해보자 -> 내 ISP가 IPv6 지원을 안함 

4. 그냥 바로 실패해버림!!!! 왜냐 지원을 안하니까!!!! 

 

그래서 내 서버에서 Ipv6를 끄니까 됏음 

 

 

다른 해결책: 

NODE_OPTIONS='--network-family-autoselection-attempt-timeout=500'

 

 

또는 

 

--no-network-family-autoselection

 

를 세팅하세요. 

 

 

 

두줄요약:

1. 노드가 happy eyeballs 구현잘못함 

2. 설정값을주셈