Skip to content

[Bug]: Issue: Discord Gateway fetch failed in WSL (Node fetch doesn’t respect proxy, undici ProxyAgent works) #25507

@liang9886703

Description

@liang9886703

Summary

After enabling Discord channel in WSL, OpenClaw fails to fetch Discord Gateway; Node built-in fetch times out despite proxy being configured, while curl works.

Steps to reproduce

Run OpenClaw inside WSL2 (Ubuntu).
Configure Discord channel with a valid bot token.
"discord": { "enabled": true, "proxy": "http://127.0.0.1:33210", …… }
Ensure HTTP proxy is enabled (e.g. Clash on Windows, proxy exposed at 127.0.0.1:).
Start OpenClaw with Discord channel enabled.

Expected behavior

OpenClaw should successfully fetch Discord Gateway information and establish a connection to Discord.

Actual behavior

Discord channel initialization fails with an error similar to:

Failed to get gateway information from Discord: fetch failed
cause: AggregateError [ETIMEDOUT]
No Discord connection is established, and the channel is marked as unavailable.

OpenClaw version

2026.2.22-2

Operating system

Windows 11 WSL2 (Ubuntu)

Install method

npm install -g openclaw@latest

Logs, screenshots, and evidence

1. curl works correctly
curl https://discord.com/api/v10/gateway/bot
Response:

{"message":"401: Unauthorized","code":0}
This confirms:

Network connectivity is fine
TLS handshake succeeds
Discord API is reachable
2. Node built-in fetch fails
node -e "fetch('https://discord.com/api/v10/gateway/bot').then(r=>console.log(r.status)).catch(console.error)"
Output:

TypeError: fetch failed
cause: AggregateError [ETIMEDOUT]
3. Explicit undici ProxyAgent works
import { request, ProxyAgent, setGlobalDispatcher } from 'undici';

setGlobalDispatcher(
  new ProxyAgent('http://127.0.0.1:<proxy-port>')
);

request('https://discord.com/api/v10/gateway/bot')
  .then(r => console.log(r.statusCode))
  .catch(console.error);
Output:

401
This confirms the issue is not Discord, not network, but Node fetch not using proxy.

Impact and severity

Affected systems: OpenClaw users running in WSL with Discord channel enabled
Severity: High (Discord channel completely unusable)
Frequency: 100% reproducible
Consequence:
Discord gateway cannot be initialized
Discord channel cannot be used at all
Users are blocked unless they move off WSL or patch networking manually

Additional information

Root cause (analysis)
Node.js built-in fetch (implemented via undici) does not reliably respect system proxy / HTTP_PROXY / HTTPS_PROXY in WSL environments.

As a result:

DNS resolution succeeds
Multiple IPs are attempted
TCP connections time out before reaching the proxy
Explicitly configuring undici with ProxyAgent fully resolves the issue.

Suggested fix / workaround
Recommended fix (production-safe):

Configure undici global dispatcher before any fetch / Discord initialization:

import { ProxyAgent, setGlobalDispatcher } from 'undici';

setGlobalDispatcher(
new ProxyAgent(process.env.HTTP_PROXY)
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions