From 2a8da25d26e851c73e533157a7aa7a89f72c8cec Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sat, 2 May 2026 19:34:48 +0800 Subject: [PATCH] chore: handle the possibility of multiple ClientTrace.GotConn calls --- transport/xhttp/client.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/transport/xhttp/client.go b/transport/xhttp/client.go index 7f5c379f4..08efc3599 100644 --- a/transport/xhttp/client.go +++ b/transport/xhttp/client.go @@ -354,7 +354,10 @@ func (c *Client) DialStreamOne(ctx context.Context) (net.Conn, error) { addrCtx := httputils.NewAddrContext(&conn.NetAddr, reqCtx) streamCtx := httptrace.WithClientTrace(addrCtx, &httptrace.ClientTrace{ GotConn: func(info httptrace.GotConnInfo) { - gotConn <- true + select { + case gotConn <- true: + default: // GotConn maybe called multiple times, ignore the second and later calls + } }, }) @@ -452,7 +455,10 @@ func (c *Client) DialStreamUp(ctx context.Context) (net.Conn, error) { addrCtx := httputils.NewAddrContext(&conn.NetAddr, reqCtx) downloadCtx := httptrace.WithClientTrace(addrCtx, &httptrace.ClientTrace{ GotConn: func(info httptrace.GotConnInfo) { - gotConn <- true + select { + case gotConn <- true: + default: // GotConn maybe called multiple times, ignore the second and later calls + } }, }) @@ -596,7 +602,10 @@ func (c *Client) DialPacketUp(ctx context.Context) (net.Conn, error) { addrCtx := httputils.NewAddrContext(&conn.NetAddr, reqCtx) downloadCtx := httptrace.WithClientTrace(addrCtx, &httptrace.ClientTrace{ GotConn: func(info httptrace.GotConnInfo) { - gotConn <- true + select { + case gotConn <- true: + default: // GotConn maybe called multiple times, ignore the second and later calls + } }, })