go network_error ai_generated true

rpc错误:代码=不可用 描述=连接错误:描述=“传输:拨号时出错:拨号tcp:在8.8.8.8:53上查找myservice:无此主机”

rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial tcp: lookup myservice on 8.8.8.8:53: no such host"

ID: go/grpc-unavailable-dns-probe

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-10-01首次发现

版本兼容性

版本状态引入弃用备注
1.20 active — — —
1.21 active — — —

根因分析

DNS服务器无法解析gRPC服务主机名,通常是由于DNS配置错误或服务名称拼写错误。

English

The DNS server cannot resolve the gRPC service hostname, often due to incorrect DNS configuration or service name typo.

generic

解决方案

  1. 90% 成功率 Use the service's IP address directly in the dial string.
    conn, err := grpc.Dial("10.0.0.5:50051", grpc.WithInsecure())
  2. 85% 成功率 Add the hostname to /etc/hosts or use a custom resolver.
    net.DefaultResolver = &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { d := net.Dialer{}; return d.DialContext(ctx, "udp", "192.168.1.1:53") }}

无效尝试

常见但无效的做法:

  1. Adding a random retry delay. 95% 失败

    DNS resolution still fails; delay doesn't fix the lookup.

  2. Changing the DNS server to a public one like 1.1.1.1. 70% 失败

    Public DNS may not have the private service record.