go network_error ai_generated true

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active — — —
1.21 active — — —

Root Cause

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

generic

中文

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

Workarounds

  1. 90% success Use the service's IP address directly in the dial string.
    conn, err := grpc.Dial("10.0.0.5:50051", grpc.WithInsecure())
  2. 85% success 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") }}

Dead Ends

Common approaches that don't work:

  1. Adding a random retry delay. 95% fail

    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% fail

    Public DNS may not have the private service record.