{"record":{"id":"f4fbbff75ffbef58","repo":"xai-org/grok-build","slug":"websocket-connection-timed-out-after-seconds","errorCode":null,"errorMessage":"WebSocket connection timed out after {} seconds","messagePattern":"WebSocket connection timed out after (.+?) seconds","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/agent/relay.rs","lineNumber":450,"sourceCode":"                Ok((ws, resp))\n            } else {\n                // The default connector never sees the shared trust config.\n                let connector =\n                    tokio_tungstenite::Connector::Rustls(xai_grok_extra_ca::rustls_client_config());\n                connect_async_tls_with_config(req, None, false, Some(connector))\n                    .await\n                    .map_err(|e| anyhow::Error::from(e).context(\"WebSocket connection failed\"))\n            }\n        }) => {\n            match result {\n                Ok(Ok((ws, resp))) => {\n                    if let Some(proto) = resp.headers().get(\"Sec-WebSocket-Protocol\") {\n                        info!(subprotocol = ?proto, \"WS subprotocol negotiated\");\n                    }\n                    Ok(ws)\n                }\n                Ok(Err(e)) => Err(e),\n                Err(_) => anyhow::bail!(\"WebSocket connection timed out after {} seconds\", CONNECT_TIMEOUT_SECS),\n            }\n        }\n    }\n}\n/// Run a single WebSocket session, handling messages until disconnection.\npub(crate) async fn run_websocket_session<S>(\n    ws: tokio_tungstenite::WebSocketStream<S>,\n    to_agent_tx: &mpsc::UnboundedSender<String>,\n    from_agent_rx: &mut mpsc::UnboundedReceiver<String>,\n    cancel: &CancellationToken,\n) -> anyhow::Result<SessionEndReason>\nwhere\n    S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + 'static,\n{\n    run_websocket_session_with_liveness(\n        ws,\n        to_agent_tx,\n        from_agent_rx,","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/agent/relay.rs#L432-L468","documentation":"connect_to_relay wraps the WebSocket handshake in tokio::time::timeout with CONNECT_TIMEOUT_SECS. If the handshake future is still pending when the timeout elapses, the elapsed branch bails with \"WebSocket connection timed out after {N} seconds\".","triggerScenarios":"The WS handshake (optionally via proxy CONNECT + TLS + tokio-tungstenite handshake) does not complete within CONNECT_TIMEOUT_SECS — the timeout Err(_) arm fires.","commonSituations":"Relay host unreachable (packets silently dropped by firewall); DNS resolving but routing black-holed; very slow network or heavily loaded proxy; wrong relay origin/host configured.","solutions":["Verify network connectivity to the relay host/port (curl or ping the host).","Check firewall/VPN rules — silent drops (no RST) are the usual cause of a full-timeout rather than a refused error.","Confirm the relay URL/origin configuration points at the correct host.","Retry with backoff; if behind a proxy, test whether the proxy is the bottleneck (also see proxy CONNECT errors)."],"exampleFix":"// before\nlet ws = connect_to_relay(&config, &cancel, proxy).await?;\n// after\nlet ws = retry_with_backoff(3, || async {\n    connect_to_relay(&config, &cancel, proxy).await\n}).await?;","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match connect_to_relay(&config, &cancel, proxy).await {\n    Err(e) if e.to_string().contains(\"timed out after\") => {\n        // retry with backoff, then surface a clear connectivity error\n        retry_with_backoff(3, || connect_to_relay(&config, &cancel, proxy)).await\n            .context(\"relay unreachable: check network/firewall and relay host\")\n    }\n    other => other,\n}","preventionTips":["Verify relay host/port reachability before starting sessions in restricted networks","Check firewall/VPN rules — silent packet drops cause full timeouts rather than refused errors","Retry with exponential backoff for transient network issues","Validate the relay origin configuration points at the correct host"],"tags":["websocket","timeout","network","relay","connectivity"],"backgroundTag":"connection-timed-out","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}