derailed/k9s · error

dialLogs - no connection to dial

Error message

dialLogs - no connection to dial

What it means

Returned by APIClient.DialLogs (internal/client/client.go:441) when getConnOK() is false. DialLogs lazily builds a dedicated clientset for log streaming (it zeroes cfg.Timeout so streaming is never cut off), but only after the connection health flag is verified. The guard mirrors Dial(): a failed connectivity check poisons every dial path until reconnection.

Solutions

  1. Call CheckConnectivity() and reconnect until it returns true, then retry DialLogs
  2. Fix the underlying connectivity (VPN, kubeconfig server URL, exec-credential expiry) and re-run the connection check
  3. Ensure the code does not cache a failed APIClient across context switches — recreate it after switching clusters

Example fix

// before
conn, err := apiClient.DialLogs()

// after
if apiClient.CheckConnectivity() {
    conn, err := apiClient.DialLogs()
}
// otherwise report 'no API server connection' to the user and stop
Defensive patterns

Strategy: validation

Validate before calling

if !apiClient.CheckConnectivity() {
    return nil, errors.New("logs unavailable: api server down")
}
conn, err := apiClient.DialLogs()

Try / catch

conn, err := apiClient.DialLogs()
if err != nil {
    if strings.Contains(err.Error(), "no connection to dial") {
        ui.NotifyError("Connection lost — reconnecting")
        if apiClient.CheckConnectivity() {
            conn, err = apiClient.DialLogs() // one retry after reconnect
        }
    }
}

Prevention

When it happens

Trigger: Invoking DialLogs() after CheckConnectivity() marked the connection down (ServerVersion probe failure, RESTConfig error, panic in the check), or before any successful connection was established in this process.

Common situations: Viewing pod logs right after the laptop wakes from sleep and the API server is temporarily unreachable; API server restart; proxy/load-balancer dropped the session; using a client that was constructed but never connected.

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/a6118ac8846d04b1. Report an issue: GitHub.

Appendix: source

Thrown at internal/client/client.go:441

func (a *APIClient) setClient(k kubernetes.Interface) {
	a.mx.Lock()
	defer a.mx.Unlock()

	a.client = k
}

func (a *APIClient) getClient() kubernetes.Interface {
	a.mx.RLock()
	defer a.mx.RUnlock()

	return a.client
}

// DialLogs returns a handle to api server for logs.
func (a *APIClient) DialLogs() (kubernetes.Interface, error) {
	if !a.getConnOK() {
		return nil, errors.New("dialLogs - no connection to dial")
	}
	if clt := a.getLogClient(); clt != nil {
		return clt, nil
	}

	cfg, err := a.RestConfig()
	if err != nil {
		return nil, err
	}
	cfg.Timeout = 0
	c, err := kubernetes.NewForConfig(cfg)
	if err != nil {
		return nil, err
	}
	a.setLogClient(c)

	return a.getLogClient(), nil
}

View on GitHub (pinned to 2d3ccc6ba2)