From cd53e2d4a7a1c936b60877bb8df8638b07d0b87c Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sun, 27 Nov 2022 16:38:41 +0800 Subject: [PATCH] fix: set RequestTimeout in earlyConn --- transport/tuic/client.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/transport/tuic/client.go b/transport/tuic/client.go index e31cdb82..a2057bd1 100644 --- a/transport/tuic/client.go +++ b/transport/tuic/client.go @@ -291,10 +291,7 @@ func (t *Client) DialContext(ctx context.Context, metadata *C.Metadata) (net.Con return nil, err } - if t.RequestTimeout > 0 { - _ = stream.SetReadDeadline(time.Now().Add(time.Duration(t.RequestTimeout) * time.Millisecond)) - } - conn := &earlyConn{BufferedConn: N.NewBufferedConn(stream)} + conn := &earlyConn{BufferedConn: N.NewBufferedConn(stream), RequestTimeout: t.RequestTimeout} if !t.FastOpen { err = conn.Response() if err != nil { @@ -308,9 +305,14 @@ type earlyConn struct { *N.BufferedConn resOnce sync.Once resErr error + + RequestTimeout int } func (conn *earlyConn) response() error { + if conn.RequestTimeout > 0 { + _ = conn.SetReadDeadline(time.Now().Add(time.Duration(conn.RequestTimeout) * time.Millisecond)) + } response, err := ReadResponse(conn) if err != nil { _ = conn.Close()