chenhg5/cc-connect · error
dial: %w
Error message
dial: %w
What it means
runConnection dials the WeCom WebSocket endpoint with websocket.DefaultDialer.DialContext; this error wraps any dial failure. The connectLoop caller typically retries with backoff, so this error is an intermediate, retryable failure describing why the TCP/TLS/WebSocket handshake did not complete.
Source
Thrown at platform/wecom/websocket.go:193
case <-time.After(backoff):
case <-p.ctx.Done():
return
}
backoff *= 2
if backoff > wsMaxBackoff {
backoff = wsMaxBackoff
}
}
}
// runConnection dials, subscribes, and processes messages until disconnection.
func (p *WSPlatform) runConnection() error {
slog.Info("wecom-ws: connecting", "endpoint", wsEndpoint)
conn, _, err := websocket.DefaultDialer.DialContext(p.ctx, wsEndpoint, nil)
if err != nil {
return fmt.Errorf("dial: %w", err)
}
p.mu.Lock()
p.conn = conn
p.mu.Unlock()
defer func() {
p.mu.Lock()
p.conn = nil
p.mu.Unlock()
conn.Close()
// Drain pending ACK channels so waiting goroutines are unblocked
// and stale entries do not accumulate across reconnections.
// Collect keys first, then delete — Range+Delete in callback is
// not guaranteed safe by the sync.Map contract.
var staleKeys []any
p.pendingAcks.Range(func(key, value any) bool {View on GitHub (pinned to 4000b2338a)
Solutions
- Check basic connectivity to the WeCom websocket endpoint (DNS, firewall, proxy).
- Inspect the wrapped cause: 'connection refused' vs 'no such host' vs 'context canceled' point to different fixes.
- If it is 'context canceled', the platform was shutting down — no action needed; the connect loop should stop.
- Add a proxy configuration if the host requires one to reach external wss:// endpoints.
- Rely on connectLoop backoff for transient network blips; alert only if it never recovers.
Example fix
null
Defensive patterns
Strategy: retry
Validate before calling
conn, err := net.DialTimeout("tcp", hostPort, 5*time.Second)
if err != nil { return fmt.Errorf("endpoint unreachable: %w", err) } // pre-check before starting the platform Type guard
null
Try / catch
if err := platform.Start(ctx); err != nil {
if errors.Is(err, context.Canceled) { return nil } // expected during shutdown
backoffRetry(err)
} Prevention
- Pre-check DNS/firewall reachability of the wss endpoint
- Configure proxy settings where required
- Alert on connectLoop exhausting retries rather than single failures
When it happens
Trigger: DialContext fails due to DNS resolution failure, unreachable host, refused TCP connection, TLS handshake error, or context cancellation (p.ctx done) during the dial.
Common situations: Corporate firewall/proxy blocking wss:// traffic to the WeCom endpoint; DNS misconfiguration; machine offline or network flapping; p.ctx canceled during shutdown producing 'context canceled' wrapped here.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- wecom-ws: ack timeout
- subscribe: %w
- upload init: %w
- read register_ack: %w
- cloud_web: websocket disconnected
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/43d96b4c148b964d.
Report an issue: GitHub.