| title | How to Fix OpenCode Network Errors on Linux |
|---|---|
| description | Step-by-step technical guide to diagnosing and fixing OpenCode ETIMEDOUT, ECONNRESET, and DNS network errors on Linux with isolated user-space proxies. |
When working with command-line AI coding tools like OpenCode on Linux, network drops, broken TCP sockets, and DNS resolution failures can halt development sessions. This guide explains why OpenCode network errors occur on Linux (verified on Ubuntu 24.04 LTS x86_64), provides diagnostic techniques, and details practical solutions including process-isolated proxy routing with OpenCode Router.
Terminal error logs from OpenCode generally manifest in three forms:
-
Socket Connection Timeouts (
ETIMEDOUT):Error: connect ETIMEDOUT 198.51.100.45:443 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)Cause: The target API endpoint or intermediate CDN firewall dropped the initial TCP SYN packet without responding. Often caused by regional network filtering or ISP-level throttling.
-
Connection Resets & Broken TLS Handshakes (
ECONNRESET):Error: read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)Cause: Deep packet inspection (DPI) or an upstream gateway severed the TLS handshake midway during certificate negotiation.
-
DNS Lookup Failures (
ENOTFOUND/EAI_AGAIN):Error: getaddrinfo ENOTFOUND api.deepseek.comCause: Local DNS resolver issues or recursive DNS poisoning preventing resolution of AI provider hostnames.
Before applying fixes, run these diagnostic checks in your terminal to isolate the root cause:
Test whether your host network can reach the provider's HTTPS endpoint over standard port 443:
# Test raw TCP handshake latency (substitute with your provider endpoint)
curl -Iv --connect-timeout 5 https://api.deepseek.com- If the command hangs at
* Connecting to ..., your direct network connection is blocked or severely throttled. - If it connects and completes the TLS handshake (
* SSL connection using TLSv1.3), the issue may be client-side or related to rate limits.
Inspect your active OpenCode configuration:
cat ~/.config/opencode/opencode.jsonVerify that the model identifier and endpoint URLs are valid and match your intended provider.
Run a deterministic test with a minimal payload to eliminate prompt rendering delays:
opencode run "Reply with: OK" --pureIf this command exits with a timeout or network error, proceeding with proxy configuration is recommended.
The standard workaround of activating a system-wide VPN is often counterproductive for developers because it redirects all host traffic, terminating active SSH connections, local databases, and development servers.
A superior approach is process-level proxy routing: routing OpenCode strictly through a local user-space proxy while leaving the rest of your operating system untouched.
If you already run a local SOCKS5 or HTTP proxy (such as on ports 10808 or 10809):
# Inject proxy variables specifically for a single OpenCode execution
http_proxy="http://127.0.0.1:10809" \
https_proxy="http://127.0.0.1:10809" \
all_proxy="socks5://127.0.0.1:10808" \
opencode run "Your prompt here"OpenCode Router automates this entire pipeline:
- Discovers and normalizes VLESS, VMess, Trojan, and Shadowsocks nodes from verified sources.
- Performs a 3-stage health probe (TCP reachability -> proxy egress handshake -> real OpenCode test execution).
- Automatically switches configurations if a node experiences network drops or socket resets.
- Provides a pre-configured launcher (
bin/opencode-vpn) that sets local environment variables exclusively for OpenCode:
# Run through verified low-latency proxy
bin/opencode-vpn run "Explain quicksort in TypeScript" --pureOpenCode relies on standard Node.js and libuv networking libraries, which respect the environment variables all_proxy, ALL_PROXY, http_proxy, and https_proxy. Passing all_proxy="socks5://127.0.0.1:10808" routes all TCP traffic through the local SOCKS5 inbound listener.
By default, command-line AI clients may wait for several minutes for a hanging HTTP stream before timing out. Setting an explicit timeout in your wrapper or using OpenCode Router's latency tester ensures fast-fail detection within 15 seconds.
Switching to public DNS resolvers (such as Cloudflare 1.1.1.1 or Google 8.8.8.8) resolves ENOTFOUND errors, but does not resolve TCP blocking or DPI throttling. For connection resets (ECONNRESET), encrypted proxy tunnels (such as VLESS with Reality or TLS) are necessary.