fix(ide): add async DNS check for host.docker.internal in container environments#1817
Conversation
…nvironments In container environments like code-server where host.docker.internal may not be configured, the IDE client would fail to connect. This change makes getIdeServerHost() async and adds a DNS lookup to verify the hostname is actually resolvable before using it, falling back to 127.0.0.1 if not. Co-authored-by: Cursor <cursoragent@cursor.com>
📋 Review SummaryThis PR addresses an important issue where the IDE client connection fails in container environments where 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
packages/core/src/ide/ide-client.ts
Outdated
| */ | ||
| function checkHostReachable(hostname: string): Promise<boolean> { | ||
| return new Promise((resolve) => { | ||
| dns.lookup(hostname, (err) => { |
There was a problem hiding this comment.
dns.lookup has no timeout — under poor network conditions it could block for tens of seconds. Consider wrapping it with a ~3s setTimeout fallback to keep the connection flow snappy.
Rest looks great, solid test coverage 👍
There was a problem hiding this comment.
Implemented this locally: checkHostReachable now wraps dns.lookup with a 3s timeout fallback, so connection setup will not stall if DNS hangs. On timeout we log debug info and return false (which falls back to 127.0.0.1).
Also added a unit test for the timeout path (simulated hanging lookup with fake timers), and restored real timers in afterEach to avoid timer leakage between tests. I will push the branch update next.
…ocker-ide-host-check
…plication - Add 3-second timeout for DNS lookup in container environments - Implement in-flight promise caching to prevent redundant concurrent DNS queries - Pass ideHost to createProxyAwareFetch to properly configure NO_PROXY Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
…l, Dev Container) - Detect cloud IDE environments via environment variables - Use host.docker.internal for IDE server connection in containers - Add DNS lookup with timeout and fallback to 127.0.0.1 - Improve error messages and troubleshooting guidance for cloud IDEs - Update /ide status, /ide install, and /ide enable commands with cloud-specific info Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
…nnection logic - Remove isCloudIdeRuntime, getCloudIdeEnvironmentLabels functions - Remove DEVCONTAINER detection in detect-ide - Simplify ideCommand by removing cloud IDE special handling - Refactor getIdeServerHost to use dns.promises.lookup - Use single promise cache for IDE server host resolution Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
…nments - Retry HTTP connection with 127.0.0.1 when host.docker.internal fails - Scan IDE lock directory when env var and legacy config are unavailable - Handle code-server scenario where extension runs inside container Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Add FileHandle type import and fix the mock function parameter type to match fs.promises.readFile signature (PathLike | FileHandle).
- Always try localhost first in HTTP connection, then fallback to host.docker.internal when in container environment - Return undefined when scanned lock files do not match current workspace instead of returning the first config Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
TLDR
Fix IDE client connection failure in container environments (e.g. code-server / WebIDE) where
host.docker.internalis not available. ThegetIdeServerHost()function is now async and performs a DNS lookup to verifyhost.docker.internalis resolvable before using it, automatically falling back to127.0.0.1when it is not.Dive Deeper
Problem
In Docker Desktop,
host.docker.internalis automatically configured to resolve to the host machine. However, this hostname may not exist in:--add-host=host.docker.internal:host-gatewayThe previous implementation detected container environments via
/.dockerenvor/run/.containerenvand unconditionally usedhost.docker.internal, causing IDE connection failures in environments where that hostname is unresolvable.Changes
getIdeServerHost(): Now performs adns.lookupto check ifhost.docker.internalis resolvable before using it_resetCachedIdeServerHost()for test isolationReviewer Test Plan
npx vitest run packages/core/src/ide/ide-client.test.tshost.docker.internalconfigured, verify IDE connects normallyhost.docker.internal, verify IDE falls back to127.0.0.1Testing Matrix
Linked issues / bugs
Fixes #1567