{"record":{"id":"efa234411819eed0","repo":"derailed/k9s","slug":"no-connection-to-dial","errorCode":null,"errorMessage":"no connection to dial","messagePattern":"no connection to dial","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/client.go","lineNumber":464,"sourceCode":"\n\tcfg, err := a.RestConfig()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcfg.Timeout = 0\n\tc, err := kubernetes.NewForConfig(cfg)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ta.setLogClient(c)\n\n\treturn a.getLogClient(), nil\n}\n\n// Dial returns a handle to api server or die.\nfunc (a *APIClient) Dial() (kubernetes.Interface, error) {\n\tif !a.getConnOK() {\n\t\treturn nil, errors.New(\"no connection to dial\")\n\t}\n\tif c := a.getClient(); c != nil {\n\t\treturn c, nil\n\t}\n\n\tcfg, err := a.RestConfig()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tc, err := kubernetes.NewForConfig(cfg)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ta.setClient(c)\n\n\treturn a.getClient(), nil\n}\n","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/client/client.go#L446-L482","documentation":"Returned by APIClient.Dial (internal/client/client.go:464) when the connOK flag is false. Dial is the primary lazy constructor for the shared kubernetes.Interface clientset: it returns the cached client if present, otherwise builds one from RestConfig(). The connOK gate is the single health latch shared by CanI, DialLogs, Dial and CachedDiscovery, flipped off by any failed connectivity probe.","triggerScenarios":"Calling Dial() after CheckConnectivity() failed (RESTConfig error, kubernetes.NewForConfig error, or ServerVersion() error), or on a freshly created client that never connected.","commonSituations":"Working offline or on a flaky link; kubeconfig context pointing to a decommissioned cluster; the API server restarting during a session; automated tests that build an APIClient without a live cluster.","solutions":["Verify and restore connectivity first: kubectl get --raw /readyz, then CheckConnectivity() until true","Recreate/re-init the APIClient (its caches and clients were reset when the connection dropped)","Correct the kubeconfig (server, certificate-authority, exec credentials) if RESTConfig() itself errors","Treat repeated failures as a fatal session error rather than looping"],"exampleFix":"// before\nc, err := apiClient.Dial()\n\n// after\nif !apiClient.CheckConnectivity() {\n    return nil, fmt.Errorf(\"cannot dial: api server connection is down\")\n}\nc, err := apiClient.Dial()","handlingStrategy":"validation","validationCode":"if apiClient.CheckConnectivity() {\n    c, err := apiClient.Dial()\n    // use c\n}","typeGuard":null,"tryCatchPattern":"c, err := apiClient.Dial()\nif err != nil {\n    if strings.Contains(err.Error(), \"no connection to dial\") {\n        // precondition: reconnect or surface fatal 'cluster unreachable' to user\n    }\n    return err\n}","preventionTips":["Dial through a single wrapper that validates connectivity first","Never persist a kubernetes.Interface obtained before a failed connectivity check","On CI, fail fast with a clear message when the cluster is unreachable rather than retrying in a loop"],"tags":["kubernetes","connection","clientset","lazy-init"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}