{"record":{"id":"4d6b4098ff29932f","repo":"vitessio/vitess","slug":"cannot-dial-to-server-v-v","errorCode":null,"errorMessage":"cannot dial to server %v: %v","messagePattern":"cannot dial to server (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"go/vt/vtctl/vtctlclient/wrapper.go","lineNumber":41,"sourceCode":"\t\"io\"\n\t\"time\"\n\n\tlogutilpb \"vitess.io/vitess/go/vt/proto/logutil\"\n)\n\nvar defaultTimeout = time.Hour\n\n// RunCommandAndWait executes a single command on a given vtctld and blocks until the command did return or timed out.\n// Output from vtctld is streamed as logutilpb.Event messages which\n// have to be consumed by the caller who has to specify a \"recv\" function.\nfunc RunCommandAndWait(ctx context.Context, server string, args []string, recv func(*logutilpb.Event)) error {\n\tif recv == nil {\n\t\treturn errors.New(\"no function closure for Event stream specified\")\n\t}\n\t// create the client\n\tclient, err := New(ctx, server)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot dial to server %v: %v\", server, err)\n\t}\n\tdefer client.Close()\n\n\t// run the command ( get the timeout from the context )\n\ttimeout := defaultTimeout\n\tdeadline, ok := ctx.Deadline()\n\tif ok {\n\t\ttimeout = time.Until(deadline)\n\t}\n\tstream, err := client.ExecuteVtctlCommand(ctx, args, timeout)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot execute remote command: %v\", err)\n\t}\n\n\t// stream the result\n\tfor {\n\t\te, err := stream.Recv()\n\t\tswitch err {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/vtctlclient/wrapper.go#L23-L59","documentation":"RunCommandAndWait dials the vtctl server using vtctlclient.New and wraps any dial/creation failure with 'cannot dial to server <addr>: <cause>'. It signals the client could not establish a connection (or was created at all) before running the command. The underlying cause (network refusal, unknown protocol, TLS) is preserved in %v.","triggerScenarios":"Calling vtctlclient.RunCommandAndWait(ctx, server, args, recv, ...) when the vtctld/vtctlserver address is wrong, the server is down, the port is closed, or New() fails due to an unregistered protocol.","commonSituations":"vtctld not running or crashed; wrong -vtctl_server address/port; firewall or k8s service misrouting; DNS failure; server upgraded while client uses incompatible protocol.","solutions":["Verify the vtctl server address and port are correct and the server process is healthy (curl/grpc probe the endpoint)","Check network reachability: firewall rules, k8s Service/Endpoints, DNS resolution for the addr","Confirm the vtctl client protocol flag matches the server and the implementation is linked (see 'unknown vtctl client protocol')","Restart or redeploy vtctld if it crashed, then retry the command"],"exampleFix":"// before\nvtctlclient.RunCommandAndWait(ctx, \"localhost:15999\", args, nil, true)\n// after\n// confirm server is up, then use the real address\nvtctlclient.RunCommandAndWait(ctx, \"vtctld.example.com:15999\", args, nil, true)","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", addr, 2*time.Second)\nif err != nil {\n  return fmt.Errorf(\"vtctl server unreachable at %s: %w\", addr, err)\n}\nconn.Close()","typeGuard":null,"tryCatchPattern":"err := vtctlclient.RunCommandAndWait(ctx, server, args, recv, true)\nif err != nil && strings.Contains(err.Error(), \"cannot dial to server\") {\n  // backoff and retry once server health passes\n  time.Sleep(time.Second)\n  err = vtctlclient.RunCommandAndWait(ctx, server, args, recv, true)\n}","preventionTips":["Probe the vtctld port before issuing commands","Use stable service DNS names, not ephemeral pod IPs","Add readiness checks so commands wait for vtctld to be up"],"tags":["go","network","vtctl","grpc","dial"],"backgroundTag":"connection-refused","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}