go network_error ai_generated true

rpc error: code = Unavailable desc = failed to resolve service name: no such host

ID: go/grpc-unavailable-dns-resolution

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-09-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.56.x active — — —
1.57.x active — — —

Root Cause

DNS resolution fails because the target hostname does not exist or DNS server is unreachable.

generic

中文

DNS 解析失败,因为目标主机名不存在或 DNS 服务器不可达。

Workarounds

  1. 85% success
    resolver := &customResolver{}; conn, err := grpc.Dial("dns:///service.example.com:50051", grpc.WithResolvers(resolver))
  2. 90% success
    nslookup service.example.com; verify /etc/resolv.conf
  3. 80% success
    conn, err := grpc.Dial("127.0.0.1:50051", grpc.WithInsecure())

Dead Ends

Common approaches that don't work:

  1. Hardcoding an IP address instead of hostname. 60% fail

    IP may change, causing future failures.

  2. Retrying indefinitely without fixing DNS. 90% fail

    DNS issue persists.

  3. Modifying system DNS settings. 50% fail

    May not be applicable in containerized environments.