fix: dualStack confusing error on ipv4 failed connect
This commit is contained in:
parent
d099375200
commit
86cf1dd54b
1 changed files with 17 additions and 4 deletions
|
@ -162,8 +162,11 @@ func concurrentDualStackDialContext(ctx context.Context, network string, ips []n
|
||||||
|
|
||||||
func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string, ips []netip.Addr, port string, opt *option) (net.Conn, error) {
|
func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string, ips []netip.Addr, port string, opt *option) (net.Conn, error) {
|
||||||
ipv4s, ipv6s := resolver.SortationAddr(ips)
|
ipv4s, ipv6s := resolver.SortationAddr(ips)
|
||||||
preferIPVersion := opt.prefer
|
if len(ipv4s) == 0 && len(ipv6s) == 0 {
|
||||||
|
return nil, ErrorNoIpAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
preferIPVersion := opt.prefer
|
||||||
fallbackTicker := time.NewTicker(fallbackTimeout)
|
fallbackTicker := time.NewTicker(fallbackTimeout)
|
||||||
defer fallbackTicker.Stop()
|
defer fallbackTicker.Stop()
|
||||||
results := make(chan dialResult)
|
results := make(chan dialResult)
|
||||||
|
@ -182,11 +185,21 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string,
|
||||||
}()
|
}()
|
||||||
result.Conn, result.error = dialFn(ctx, network, ips, port, opt)
|
result.Conn, result.error = dialFn(ctx, network, ips, port, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wait int
|
||||||
|
if len(ipv4s) != 0 {
|
||||||
|
wait++
|
||||||
go racer(ipv4s, preferIPVersion != 6)
|
go racer(ipv4s, preferIPVersion != 6)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ipv6s) != 0 {
|
||||||
|
wait++
|
||||||
go racer(ipv6s, preferIPVersion != 4)
|
go racer(ipv6s, preferIPVersion != 4)
|
||||||
|
}
|
||||||
|
|
||||||
var fallback dialResult
|
var fallback dialResult
|
||||||
var errs []error
|
var errs []error
|
||||||
for i := 0; i < 2; {
|
for i := 0; i < wait; {
|
||||||
select {
|
select {
|
||||||
case <-fallbackTicker.C:
|
case <-fallbackTicker.C:
|
||||||
if fallback.error == nil && fallback.Conn != nil {
|
if fallback.error == nil && fallback.Conn != nil {
|
||||||
|
|
Loading…
Reference in a new issue