Merge pull request 'fixed address resolution' (#617) from tron-616 into main
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful
Reviewed-on: #617
This commit was merged in pull request #617.
This commit is contained in:
@@ -72,8 +72,36 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv
|
||||
}
|
||||
|
||||
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
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user