UNAVAILABLE
api
network_error
ai_generated
true
gRPC 错误:UNAVAILABLE:目标 dns:///my-service:50051 名称解析失败
gRPC error: UNAVAILABLE: name resolution failed for target dns:///my-service:50051
ID: api/grpc-unavailable-service-name
85%修复率
88%置信度
1证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| gRPC v1.50+ | active | — | — | — |
| gRPC-Go v1.50+ | active | — | — | — |
| gRPC-Java v1.50+ | active | — | — | — |
根因分析
DNS 解析器无法将服务主机名解析为 IP 地址,或者解析后的地址不可达。
English
The DNS resolver cannot resolve the service hostname to an IP address, or the resolved address is unreachable.
官方文档
https://grpc.io/docs/guides/errors/解决方案
-
使用 nslookup 或 dig 检查 DNS 解析:nslookup my-service。确保主机名正确且 DNS 服务器可达。如果使用 Kubernetes,验证服务名称和命名空间:kubectl get svc my-service -n your-namespace
-
直接在目标 URI 中使用 IP 地址以绕过 DNS:target ipv4:///10.0.0.1:50051,或在 gRPC 选项中配置自定义解析器。
无效尝试
常见但无效的做法:
-
60% 失败
Restarting the gRPC client without fixing DNS configuration does not resolve the underlying resolution failure.
-
30% 失败
Increasing the timeout for gRPC calls will not help if the hostname cannot be resolved at all.