fixed address resolution #617

Merged
tech merged 1 commits from tron-616 into main 2026-03-03 18:13:58 +00:00
Showing only changes of commit 41cb826d26 - Show all commits

View File

@@ -72,8 +72,36 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv
} }
func grpcForceIPv4Dialer(ctx context.Context, address string) (net.Conn, error) { func grpcForceIPv4Dialer(ctx context.Context, address string) (net.Conn, error) {
host, port, err := net.SplitHostPort(address)
if err != nil {
return nil, err
}
ips, err := net.DefaultResolver.LookupIP(ctx, "ip4", host)
if err != nil {
return nil, err
}
if len(ips) == 0 {
return nil, merrors.Internal(fmt.Sprintf("no IPv4 address found for %s", host))
}
var dialer net.Dialer var dialer net.Dialer
return dialer.DialContext(ctx, "tcp4", address) var lastErr error
for _, ip := range ips {
target := net.JoinHostPort(ip.String(), port)
conn, err := dialer.DialContext(ctx, "tcp4", target)
if err == nil {
return conn, nil
}
lastErr = err
if ctx.Err() != nil {
break
}
}
if lastErr != nil {
return nil, merrors.Internal(fmt.Sprintf("failed to dial any IPv4 address for %s: %v", host, lastErr))
}
return nil, merrors.Internal(fmt.Sprintf("failed to dial IPv4 address for %s", host))
} }
func normalizeGRPCAddress(grpcURL string) (string, bool, error) { func normalizeGRPCAddress(grpcURL string) (string, bool, error) {