henrygd/beszel · error

no websocket connection

Error message

no websocket connection

What it means

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.

Source

Thrown at internal/hub/systems/system.go:510

	if sys.WsConn != nil && sys.WsConn.IsConnected() {
		wsData, err := sys.fetchDataViaWebSocket(options)
		if err == nil {
			return wsData, nil
		}
		// close the WebSocket connection if error and try SSH
		sys.closeWebSocketConnection()
	}

	sshData, err := sys.fetchDataViaSSH(options)
	if err != nil {
		return nil, err
	}
	return sshData, nil
}

func (sys *System) fetchDataViaWebSocket(options common.DataRequestOptions) (*system.CombinedData, error) {
	if sys.WsConn == nil || !sys.WsConn.IsConnected() {
		return nil, errors.New("no websocket connection")
	}
	wsTransport := transport.NewWebSocketTransport(sys.WsConn)
	err := wsTransport.Request(context.Background(), common.GetData, options, sys.data)
	if err != nil {
		return nil, err
	}
	return sys.data, nil
}

// FetchContainerInfoFromAgent fetches container info from the agent
func (sys *System) FetchContainerInfoFromAgent(containerID string) (string, error) {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	var result string
	err := sys.request(ctx, common.GetContainerInfo, common.ContainerInfoRequest{ContainerID: containerID}, &result)
	return result, err
}

View on GitHub (pinned to b38fb7dafa)

Solutions

  1. Check the agent is running and reachable (port, firewall, docker network)
  2. Fix reverse proxy config to allow WebSocket upgrades (e.g. nginx proxy_set_header Upgrade/Connection)
  3. Restart the system's connection from the hub (toggle pause/unpause) to force reconnect
  4. Verify the system's connection type (WebSocket vs SSH) matches how the agent is deployed; fall back to SSH if WS is blocked

Example fix

// before: nginx without WS upgrade
location /api/ws { proxy_pass http://agent:45876; }
// after
location /api/ws {
  proxy_pass http://agent:45876;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
}
Defensive patterns

Strategy: retry

Validate before calling

// before requesting data
if sys.WsConn == nil || !sys.WsConn.IsConnected() {
    return errors.New("agent websocket not connected; skipping poll")
}

Try / catch

data, err := sys.fetchDataViaWebSocket(opts)
if err != nil && err.Error() == "no websocket connection" {
    time.Sleep(backoff)
    return sys.fetchDataViaWebSocket(opts) // reconnect then retry
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of henrygd/beszel@b38fb7dafa (2026-08-31). Data as JSON: /api/errors/5d3eca85130f2668. Report an issue: GitHub.