{"record":{"id":"5d3eca85130f2668","repo":"henrygd/beszel","slug":"no-websocket-connection","errorCode":null,"errorMessage":"no websocket connection","messagePattern":"no websocket connection","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hub/systems/system.go","lineNumber":510,"sourceCode":"\tif sys.WsConn != nil && sys.WsConn.IsConnected() {\n\t\twsData, err := sys.fetchDataViaWebSocket(options)\n\t\tif err == nil {\n\t\t\treturn wsData, nil\n\t\t}\n\t\t// close the WebSocket connection if error and try SSH\n\t\tsys.closeWebSocketConnection()\n\t}\n\n\tsshData, err := sys.fetchDataViaSSH(options)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn sshData, nil\n}\n\nfunc (sys *System) fetchDataViaWebSocket(options common.DataRequestOptions) (*system.CombinedData, error) {\n\tif sys.WsConn == nil || !sys.WsConn.IsConnected() {\n\t\treturn nil, errors.New(\"no websocket connection\")\n\t}\n\twsTransport := transport.NewWebSocketTransport(sys.WsConn)\n\terr := wsTransport.Request(context.Background(), common.GetData, options, sys.data)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn sys.data, nil\n}\n\n// FetchContainerInfoFromAgent fetches container info from the agent\nfunc (sys *System) FetchContainerInfoFromAgent(containerID string) (string, error) {\n\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\tdefer cancel()\n\tvar result string\n\terr := sys.request(ctx, common.GetContainerInfo, common.ContainerInfoRequest{ContainerID: containerID}, &result)\n\treturn result, err\n}\n","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/hub/systems/system.go#L492-L528","documentation":"fetchDataViaWebSocket requires an established WebSocket connection to the agent. If sys.WsConn is nil or reports disconnected, the system immediately returns 'no websocket connection' instead of attempting a request. This is the WebSocket counterpart of the SSH fetch path in fetchDataFromAgent.","triggerScenarios":"fetchDataFromAgent selects the WebSocket transport for a system configured for WebSocket mode, but the connection was never opened, was closed by the agent, timed out, or is mid-reconnect.","commonSituations":"Agent process down or restarting; hub behind a proxy without WebSocket upgrade support; firewall blocking the agent's WS port; token/network change leaving the socket closed; transient network blip between hub and agent.","solutions":["Check the agent is running and reachable (port, firewall, docker network)","Fix reverse proxy config to allow WebSocket upgrades (e.g. nginx proxy_set_header Upgrade/Connection)","Restart the system's connection from the hub (toggle pause/unpause) to force reconnect","Verify the system's connection type (WebSocket vs SSH) matches how the agent is deployed; fall back to SSH if WS is blocked"],"exampleFix":"// before: nginx without WS upgrade\nlocation /api/ws { proxy_pass http://agent:45876; }\n// after\nlocation /api/ws {\n  proxy_pass http://agent:45876;\n  proxy_http_version 1.1;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n}","handlingStrategy":"retry","validationCode":"// before requesting data\nif sys.WsConn == nil || !sys.WsConn.IsConnected() {\n    return errors.New(\"agent websocket not connected; skipping poll\")\n}","typeGuard":null,"tryCatchPattern":"data, err := sys.fetchDataViaWebSocket(opts)\nif err != nil && err.Error() == \"no websocket connection\" {\n    time.Sleep(backoff)\n    return sys.fetchDataViaWebSocket(opts) // reconnect then retry\n}","preventionTips":["Monitor agent liveness and hub logs for reconnect loops","Configure proxies for WebSocket upgrade headers","Ensure firewall/network policy allows the agent WS port","Consider SSH connection mode where WebSocket is unreliable","Set status tracking so dead connections are retried with backoff"],"tags":["websocket","network","connectivity","hub"],"backgroundTag":"websocket-disconnected","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}