-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
Hi,
I encountered an issue where fetch() always fails with Network request failed: closed before established even though the network and DNS are working fine.
Environment:
- macOS
- No proxy environment variables set
Root Cause:
After some investigation, I found that my system had two DNS servers configured:
nameserver[0]: 45.14.70.54(a locally running DNS by Clash proxy, which was offline)nameserver[1]: 223.6.6.6(a valid public DNS)
The first DNS server 45.14.70.54 was unreachable (connection timed out), but the second one 223.6.6.6 worked perfectly fine.
The problem:
It seems that lws (libwebsockets) does not fall back to the next DNS server when the first one fails or times out. Instead, it immediately throws an error.
Comparison:
| Tool | Behavior |
|---|---|
curl |
Tries first DNS → fails → automatically falls back to second DNS → succeeds ✅ |
lws |
Tries first DNS → fails → throws error immediately ❌ |
Verified with:
# First DNS - times out
nslookup www.baidu.com 45.14.70.54
# → connection timed out; no servers could be reached
# Second DNS - works fine
nslookup www.baidu.com 223.6.6.6
# → returns correct IP addressExpected behavior:
When the first DNS server is unavailable, lws should fall back to the next configured DNS server, similar to how curl handles this situation.
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels