{"record":{"id":"7d2067423d4d455e","repo":"openimsdk/open-im-server","slug":"failed-to-dial-endpoint-s-v","errorCode":null,"errorMessage":"failed to dial endpoint %s: %v","messagePattern":"failed to dial endpoint (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/common/discovery/kubernetes/kubernetes.go","lineNumber":77,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\tendpoints, err := k.clientset.CoreV1().Endpoints(k.namespace).Get(context.Background(), serviceName, metav1.GetOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get endpoints for service %s: %v\", serviceName, err)\n\t}\n\n\t// fmt.Println(\"Endpoints:\", endpoints, \"endpoints.Subsets:\", endpoints.Subsets)\n\n\tvar conns []*grpc.ClientConn\n\tfor _, subset := range endpoints.Subsets {\n\t\tfor _, address := range subset.Addresses {\n\t\t\ttarget := fmt.Sprintf(\"%s:%d\", address.IP, port)\n\t\t\t// fmt.Println(\"IP target:\", target)\n\t\t\tconn, err := grpc.Dial(target, append(k.dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))...)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to dial endpoint %s: %v\", target, err)\n\t\t\t}\n\t\t\tconns = append(conns, conn)\n\t\t}\n\t}\n\n\tk.mu.Lock()\n\tk.connMap[serviceName] = conns\n\tk.mu.Unlock()\n\n\treturn nil\n}\n\n// GetConns returns gRPC client connections for a given Kubernetes service name.\nfunc (k *KubernetesConnManager) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {\n\tk.mu.RLock()\n\n\tconns, exists := k.connMap[serviceName]\n\tk.mu.RUnlock()","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/openimsdk/open-im-server/blob/175a7bb0673eca18e9d1b10bff4f728da6b1b513/pkg/common/discovery/kubernetes/kubernetes.go#L59-L95","documentation":"After obtaining endpoint addresses, initializeConns dials each pod's IP:port with grpc.Dial. If a dial fails, it wraps the target address and underlying error. Note grpc.Dial is usually non-blocking and errors here typically reflect invalid target syntax rather than unreachability, so failures usually indicate malformed addresses.","triggerScenarios":"grpc.Dial(fmt.Sprintf(\"%s:%d\", address.IP, port), ...) fails — usually an invalid address string (bad IP from endpoint subset, empty IP) or invalid dial options; with WithBlock it can also be a connection timeout to the pod.","commonSituations":"Endpoint subsets containing not-ready or placeholder IPs; service port mismatch so the pod refuses connections; passing nil/invalid dial options; port resolved as 0.","solutions":["Log/verify the target address — an empty or malformed IP in the Endpoints subset is the most common cause.","Check the resolved svcPort matches the container's gRPC listen port.","Verify the pod is ready (endpoints only list ready addresses normally) and reachable from this pod.","Use grpc.NewClient / non-blocking Dial and treat first RPC failure as the connection error instead."],"exampleFix":"// before\nconn, err := grpc.Dial(target, append(k.dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))...)\n// after\nconn, err := grpc.NewClient(target, append(k.dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))...)\nif err != nil {\n    log.Printf(\"skip bad endpoint %s: %v\", target, err)\n    continue\n}","handlingStrategy":"retry","validationCode":"if address.IP == \"\" {\n    return errors.New(\"endpoint subset has empty IP\")\n}","typeGuard":"func validTarget(ip string, port int32) bool {\n    return net.ParseIP(ip) != nil && port > 0\n}","tryCatchPattern":"conn, err := grpc.NewClient(target, opts...)\nif err != nil {\n    return fmt.Errorf(\"dial %s: %w\", target, err)\n}","preventionTips":["Validate endpoint IPs with net.ParseIP before dialing","Use non-blocking dial (grpc.NewClient) and surface errors on first RPC","Ensure svcPort matches the container gRPC listen port"],"tags":["grpc","kubernetes","network"],"backgroundTag":"grpc-dial-failed","analyzedSha":"175a7bb0673eca18e9d1b10bff4f728da6b1b513","analyzedAt":"2026-09-04T16:52:56.821Z","contentChangedAt":"2026-09-04T16:52:56.821Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}