Skip to content

Commit

Permalink
first ip or nil IP was used for connection
Browse files Browse the repository at this point in the history
  • Loading branch information
brackendawson committed Jan 7, 2023
1 parent 379260d commit 71dad8b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ func publicUnicastOnlyDialContext(ctx context.Context, network, addr string) (ne
}
}

var dialErrs []error
connectTimeout := requestTimeoutSecs * time.Second / time.Duration(len(ipAddrs)+1)
for _, ipAddr := range ipAddrs {
ip = net.ParseIP(ipAddr)
switch {
case allowLoopback && ip.IsLoopback():
case !ip.IsGlobalUnicast() || ip.IsPrivate():
dialErrs = append(dialErrs, fmt.Errorf("forbidden address: %s", ipAddr))
continue
}

Expand All @@ -63,7 +66,8 @@ func publicUnicastOnlyDialContext(ctx context.Context, network, addr string) (ne
if nil == err {
return conn, nil
}
dialErrs = append(dialErrs, fmt.Errorf("failed to dial '%s:%s': %w", ipAddr, port, err))
}

return nil, fmt.Errorf("failed to dial port %q on any address in %q", port, ipAddrs)
return nil, fmt.Errorf("failed to dial: %q", dialErrs)
}

0 comments on commit 71dad8b

Please sign in to comment.