moghtech/komodo · error · anyhow::Error
Socket closed before login
Error message
Socket closed before login
What it means
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.
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
Example fix
// before
let ws = komodo.subscribe_to_updates().await?;
// after
let ws = loop {
match komodo.subscribe_to_updates().await {
Ok(ws) => break ws,
Err(e) if e.to_string().contains("Socket closed before login") => {
tokio::time::sleep(Duration::from_secs(2)).await;
continue;
}
Err(e) => return Err(e),
}
}; Defensive patterns
Strategy: retry
Try / catch
async fn connect_with_retry(k: &Komodo) -> Result<Ws> {
let mut last = None;
for _ in 0..3 {
match k.subscribe_to_updates().await {
Ok(ws) => return Ok(ws),
Err(e) => { last = Some(e); tokio::time::sleep(Duration::from_secs(2)).await; }
}
}
Err(last.unwrap().context("websocket closed before login after retries"))
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Proxy not configured to forward WebSocket upgrade requests; TLS issues; Komodo core restarting during deploy; firewall killing the connection.
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
- Failed to log in |
- Connection closed
- Connection already closed
- Cannot insert Service type configuration as additional…
- {e:?}
AI-assisted analysis of moghtech/komodo@780ac68b99 (2026-09-08).
Data as JSON: /api/errors/38ba475174935e86.
Report an issue: GitHub.
Appendix: source
Thrown at client/core/rs/src/ws/mod.rs:78
.await
.context("Failed to send websocket login message")?;
loop {
match ws
.try_next()
.await
.context("Failed to receive websocket login response")?
{
Some(tungstenite::Message::Text(msg)) => {
if msg == "LOGGED_IN" {
return Ok(ws);
} else {
let _ = ws.close(None).await;
return Err(anyhow!("Failed to log in | {msg}"));
}
}
Some(tungstenite::Message::Close(_)) | None => {
let _ = ws.close(None).await;
return Err(anyhow!("Socket closed before login"));
}
// Keep looping on other message types
Some(_) => {}
};
}
}
}
View on GitHub (pinned to 780ac68b99)