go
network_error
ai_generated
true
rpc 错误:代码 = Unavailable 描述 = 无法解析服务名称:没有这样的主机
rpc error: code = Unavailable desc = failed to resolve service name: no such host
ID: go/grpc-unavailable-dns-resolution
80%修复率
85%置信度
0证据数
2024-09-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.56.x | active | — | — | — |
| 1.57.x | active | — | — | — |
根因分析
DNS 解析失败,因为目标主机名不存在或 DNS 服务器不可达。
English
DNS resolution fails because the target hostname does not exist or DNS server is unreachable.
解决方案
-
85% 成功率
resolver := &customResolver{}; conn, err := grpc.Dial("dns:///service.example.com:50051", grpc.WithResolvers(resolver)) -
90% 成功率
nslookup service.example.com; verify /etc/resolv.conf
-
80% 成功率
conn, err := grpc.Dial("127.0.0.1:50051", grpc.WithInsecure())
无效尝试
常见但无效的做法:
-
Hardcoding an IP address instead of hostname.
60% 失败
IP may change, causing future failures.
-
Retrying indefinitely without fixing DNS.
90% 失败
DNS issue persists.
-
Modifying system DNS settings.
50% 失败
May not be applicable in containerized environments.