Skip to content

Commit 7b73775

Browse files
committed
chore: add short circuit logic for dual stack dial to decrease unnecessary goroutine
1 parent 96a6962 commit 7b73775

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

component/dialer/dialer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string,
209209
if len(ipv4s) == 0 && len(ipv6s) == 0 {
210210
return nil, ErrorNoIpAddress
211211
}
212+
if len(ipv4s) == 0 && len(ipv6s) != 0 {
213+
return dialFn(ctx, network, ipv6s, port, opt)
214+
}
215+
if len(ipv4s) != 0 && len(ipv6s) == 0 {
216+
return dialFn(ctx, network, ipv4s, port, opt)
217+
}
212218

213219
preferIPVersion := opt.prefer
214220
fallbackTicker := time.NewTicker(dualStackFallbackTimeout)
@@ -289,6 +295,9 @@ func parallelDialContext(ctx context.Context, network string, ips []netip.Addr,
289295
if len(ips) == 0 {
290296
return nil, ErrorNoIpAddress
291297
}
298+
if len(ips) == 1 {
299+
return dialContext(ctx, network, ips[0], port, opt)
300+
}
292301
results := make(chan dialResult)
293302
returned := make(chan struct{})
294303
defer close(returned)

0 commit comments

Comments
 (0)