From 5bcfe1a6c620a791ec25e23c22b2eb8ccd182eb7 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Fri, 10 Mar 2023 20:16:14 +0800 Subject: [PATCH] fix: dialer dual stack panic --- component/dialer/dialer.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/component/dialer/dialer.go b/component/dialer/dialer.go index b47b9e5b..479def67 100644 --- a/component/dialer/dialer.go +++ b/component/dialer/dialer.go @@ -182,16 +182,8 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string, go racer(ipv6s, preferIPVersion != 4) var fallback dialResult var errs []error - for { + for i := 0; i < 2; i++ { select { - case <-ctx.Done(): - if fallback.error == nil && fallback.Conn != nil { - return fallback.Conn, nil - } - if res, ok := <-results; ok && res.error == nil { - return res.Conn, nil - } - return nil, errorsJoin(errs...) case <-fallbackTicker.C: if fallback.error == nil && fallback.Conn != nil { return fallback.Conn, nil @@ -211,6 +203,10 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string, } } } + if fallback.error == nil && fallback.Conn != nil { + return fallback.Conn, nil + } + return nil, errorsJoin(errs...) } func parallelDialContext(ctx context.Context, network string, ips []netip.Addr, port string, opt *option) (net.Conn, error) {