chenhg5/cc-connect · warning
cloud_web: websocket disconnected
Error message
cloud_web: websocket disconnected
What it means
This is not a thrown error but a synthetic error passed to the onDisconnected callback when the read/write loop of an established cloud-web WebSocket exits while the transport still considered itself connected. It notifies the engine that the previously healthy connection dropped so it can schedule a reconnect. The literal string carries no underlying cause — the real reason is whatever broke the loop.
Source
Thrown at platform/cloud-web/ws.go:182
if err != nil {
_ = conn.Close()
return err
}
t.setCaps(caps)
t.mu.Lock()
if t.conn != nil {
_ = t.conn.Close()
}
t.conn = conn
t.mu.Unlock()
slog.Info("cloud_web: websocket connected", "url", t.wsURL)
connected := true
defer func() {
if connected && t.onDisconnected != nil {
t.onDisconnected(fmt.Errorf("cloud_web: websocket disconnected"))
}
}()
if t.onConnected != nil {
t.onConnected()
}
pingDone := make(chan struct{})
go func() {
defer close(pingDone)
ticker := time.NewTicker(wsPingInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
t.writeMu.Lock()
err := conn.WriteControl(websocket.PingMessage, nil, time.Now().Add(5*time.Second))View on GitHub (pinned to 4000b2338a)
Solutions
- Let the existing connectLoop reconnect (this error is the signal that triggers it) — confirm reconnect/backoff is configured
- Ensure ping/pong keepalive (wsPingPeriod/wsPongWait) is active so dead connections are detected and re-established
- Investigate why the underlying connection died: server logs, LB idle timeout settings, network stability
- Log the actual read-loop error alongside this callback so the drop cause isn't lost
Example fix
// before
t.onDisconnected(fmt.Errorf("cloud_web: websocket disconnected"))
// after (preserve the real cause)
t.onDisconnected(fmt.Errorf("cloud_web: websocket disconnected: %w", readErr)) Defensive patterns
Strategy: retry
Try / catch
// Subscribe to onDisconnected and rely on connectLoop backoff
transport.OnDisconnected(func(err error) {
slog.Warn("cloud-web disconnected; reconnect scheduled", "err", err)
}) Prevention
- Enable ping/pong keepalive so drops are detected and reconnected fast
- Set load-balancer idle timeouts longer than the ping period
- Handle onDisconnected by flushing/queuing pending sends
- Monitor disconnect frequency to catch chronic network issues
When it happens
Trigger: The connection read or write loop returns (read error, write error, server close frame, network drop) while `connected` is still true and t.onDisconnected is non-nil.
Common situations: Server restart or deploy dropping active sockets; idle connection reaped by a load balancer when ping/pong keepalive fails; network switch/VPN drop; mobile clients or flaky Wi-Fi interrupting long-lived connections.
Related errors
- read register_ack: %w
- read websocket: %w
- wecom-ws: ack timeout
- cloud_web: ws_url or base_url is required for websocket tran
- cloud_web: parse register_ack: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/8208c278c80ededa.
Report an issue: GitHub.