From 3357c09eb86860859224fee94d6f0305d0834537 Mon Sep 17 00:00:00 2001 From: kpango Date: Sun, 27 Oct 2024 13:02:04 +0900 Subject: [PATCH] fix Signed-off-by: kpango --- internal/net/dialer.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/net/dialer.go b/internal/net/dialer.go index 73ca233f504..2a5b23421d1 100644 --- a/internal/net/dialer.go +++ b/internal/net/dialer.go @@ -119,7 +119,6 @@ func NewDialer(opts ...DialerOption) (der Dialer, err error) { netpoll.SetLoadBalance(netpoll.RoundRobin) d.npDialer = netpoll.NewDialer() - d.dialer = d.dial if d.enableDNSCache { if d.dnsRefreshDuration > d.dnsCacheExpiration { @@ -330,7 +329,14 @@ func (d *dialer) dial(ctx context.Context, network, addr string) (conn Conn, err } else { conn, err = d.npDialer.DialConnection(network, addr, d.der.Timeout) if err != nil { - conn, err = d.der.DialContext(ctx, network, addr) + if conn != nil { + err = errors.Join(err, conn.Close()) + } + var ierr error + conn, ierr = d.der.DialContext(ctx, network, addr) + if ierr != nil { + err = errors.Join(err, ierr) + } } } return err