{"record":{"id":"38ba475174935e86","repo":"moghtech/komodo","slug":"socket-closed-before-login","errorCode":null,"errorMessage":"Socket closed before login","messagePattern":"Socket closed before login","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"client/core/rs/src/ws/mod.rs","lineNumber":78,"sourceCode":"      .await\n      .context(\"Failed to send websocket login message\")?;\n    loop {\n      match ws\n        .try_next()\n        .await\n        .context(\"Failed to receive websocket login response\")?\n      {\n        Some(tungstenite::Message::Text(msg)) => {\n          if msg == \"LOGGED_IN\" {\n            return Ok(ws);\n          } else {\n            let _ = ws.close(None).await;\n            return Err(anyhow!(\"Failed to log in | {msg}\"));\n          }\n        }\n        Some(tungstenite::Message::Close(_)) | None => {\n          let _ = ws.close(None).await;\n          return Err(anyhow!(\"Socket closed before login\"));\n        }\n        // Keep looping on other message types\n        Some(_) => {}\n      };\n    }\n  }\n}\n","sourceCodeStart":60,"sourceCodeEnd":86,"githubUrl":"https://github.com/moghtech/komodo/blob/780ac68b992094a9fccd5fffb760e0c84fd3c3d1/client/core/rs/src/ws/mod.rs#L60-L86","documentation":"During the websocket login handshake, the server closed the connection (Close frame) or the stream ended before the 'LOGGED_IN' confirmation arrived. The client closes its side and returns this error, meaning login could not complete because the peer hung up.","triggerScenarios":"Server terminating the websocket during the auth handshake — invalid credentials causing immediate close, server restart, reverse proxy (nginx/traefik) idle-timeout or buffering config dropping ws upgrades, network interruption.","commonSituations":"Proxy not configured to forward WebSocket upgrade requests; TLS issues; Komodo core restarting during deploy; firewall killing the connection.","solutions":["Verify the proxy in front of Komodo forwards Upgrade/Connection headers for websockets and has adequate timeouts","Retry — transient network issues or a restarting server cause this","Confirm credentials are valid; some servers close instead of answering on bad auth","Check Komodo core logs at the time of connection for why the socket closed"],"exampleFix":"// before\nlet ws = komodo.subscribe_to_updates().await?;\n// after\nlet ws = loop {\n    match komodo.subscribe_to_updates().await {\n        Ok(ws) => break ws,\n        Err(e) if e.to_string().contains(\"Socket closed before login\") => {\n            tokio::time::sleep(Duration::from_secs(2)).await;\n            continue;\n        }\n        Err(e) => return Err(e),\n    }\n};","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"async fn connect_with_retry(k: &Komodo) -> Result<Ws> {\n    let mut last = None;\n    for _ in 0..3 {\n        match k.subscribe_to_updates().await {\n            Ok(ws) => return Ok(ws),\n            Err(e) => { last = Some(e); tokio::time::sleep(Duration::from_secs(2)).await; }\n        }\n    }\n    Err(last.unwrap().context(\"websocket closed before login after retries\"))\n}","preventionTips":["Configure reverse proxies to pass websocket upgrades and raise idle timeouts","Add automatic reconnect logic for long-lived ws subscriptions","Check Komodo core health before connecting"],"tags":["websocket","network","auth"],"backgroundTag":"connection-refused","analyzedSha":"780ac68b992094a9fccd5fffb760e0c84fd3c3d1","analyzedAt":"2026-09-08T10:02:44.861Z","contentChangedAt":"2026-09-08T10:02:44.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}